首页 文章

ASP.Net 5应用程序引用.NET Framework 4.6程序集

提问于
浏览
0

我试图从我的ASP.NET 5项目中引用.NET 4.6程序集 . 我正在运行ASP.NET和Web Tools 2015(RC1 Update 1) .

我已经阅读了以下问题,但无法让它工作:ASP.NET 5 Application Reference .NET 4.6 DLL

我甚至得到了构建的项目:Referencing a .NET 4.6 project from ASP.NET 5 causes build error

当引用程序集上的目标框架设置为4.5.1时,我可以构建并运行应用程序,但只要引用程序集上的目标框架更改为4.6,编译器就会报告以下错误:

“无法找到类型或命名空间名称'ClassLibrary'(您是否缺少using指令或程序集引用?)”

下面是我的project.json文件的一些部分,其中“ClassLibrary”是我引用的.Net 4.6程序集 .

"dependencies": {
  "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
  "Microsoft.AspNet.Mvc": "6.0.0-rc1-final",
  "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
  "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.FileProviderExtensions" : "1.0.0-rc1-final",
  "Microsoft.Extensions.Configuration.Json": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Console": "1.0.0-rc1-final",
  "Microsoft.Extensions.Logging.Debug": "1.0.0-rc1-final"
},

"commands": {
  "web": "Microsoft.AspNet.Server.Kestrel"
},

"frameworks": {
  "dnx46": {
    "dependencies": {
      "ClassLibrary": "1.0.0-*"
    }
  },
},

1 回答

  • 0

    为了从 DNX 项目中使用 .NET 4.6 库,您需要正确地定位框架 . 您目前的定位 dnx46net46 不同 .

    改变这个:

    "frameworks": {
      "dnx46": {
        "dependencies": {
          "ClassLibrary": "1.0.0-*"
        }
      }
    

    对此:

    "frameworks": {
      "net46": {
        "dependencies": {
          "ClassLibrary": "1.0.0-*"
        }
      }
    

    斯科特艾伦有一篇关于DNX选项here的精彩文章 . 注意,DNX即将退休,这将很快改变 .NET Core .

相关问题