.net - 解决错误 "Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1"

标签 .net asp.net-core .net-core asp.net-core-1.0 project.json

我有一个使用 net461 运行的 ASP.NET Core 1.0 完整应用程序引用。现在我正在尝试添加另一个框架 - netcoreapp1.0 .为此,我像这样更新了我的 project.json:

{
   "userSecretsId":"",
   "version":"2.4.0-*",
   "buildOptions":{
      "emitEntryPoint":true,
      "preserveCompilationContext":true
   },
   "dependencies":{
      "Microsoft.ApplicationInsights.AspNetCore":"1.0.0",
      "Microsoft.AspNetCore.Authentication.Cookies":"1.0.0",
      "Microsoft.AspNetCore.Diagnostics":"1.0.0",
      "Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore":"1.0.0",
      "Microsoft.AspNetCore.Identity":"1.0.0",
      "Microsoft.AspNetCore.Identity.EntityFrameworkCore":"1.0.0",
      "Microsoft.AspNetCore.Mvc":"1.0.0",
      "Microsoft.AspNetCore.Mvc.TagHelpers":"1.0.0",
      "Microsoft.AspNetCore.Server.IISIntegration":"1.0.0",
      "Microsoft.AspNetCore.Server.Kestrel":"1.0.0",
      "Microsoft.AspNetCore.StaticFiles":"1.0.0",
      "Microsoft.EntityFrameworkCore":"1.0.0",
      "Microsoft.EntityFrameworkCore.SqlServer":"1.0.0",
      "Microsoft.Extensions.Configuration.CommandLine":"1.0.0",
      "Microsoft.Extensions.Configuration.FileExtensions":"1.0.0",
      "Microsoft.Extensions.Configuration.Json":"1.0.0",
      "Microsoft.Extensions.Configuration.UserSecrets":"1.0.0",
      "Microsoft.Extensions.Logging":"1.0.0",
      "Microsoft.Extensions.Logging.Console":"1.0.0",
      "Microsoft.Extensions.Logging.Debug":"1.0.0",
      "Microsoft.VisualStudio.Web.BrowserLink.Loader":"14.0.0",
      "Microsoft.VisualStudio.Web.CodeGenerators.Mvc":"1.0.0-preview2-final"
   },
   "tools":{
      "BundlerMinifier.Core":"2.0.238",
      "Microsoft.AspNetCore.Razor.Tools":"1.0.0-preview2-final",
      "Microsoft.AspNetCore.Server.IISIntegration.Tools":"1.0.0-preview2-final",
      "Microsoft.Extensions.SecretManager.Tools":"1.0.0-preview2-final"
   },
   "commands":{
      "ef":"EntityFramework.Commands",
      "web":"Microsoft.AspNetCore.Server.Kestrel"
   },
   "frameworks":{
      "net461":{

      },
      "netcoreapp1.0":{
         "imports":[
            "dotnet5.6",
            "portable-net45+win8"
         ]
      }
   },
   "runtimes":{
      "win10-x64":{

      },
      "win81-x64":{

      },
      "win8-x64":{

      },
      "win7-x64":{

      }
   },
   "publishOptions":{
      "exclude":[
         "**.user",
         "**.vspscc",
         "wwwroot",
         "node_modules"
      ]
   },
   "scripts":{
      "prepublish":[
         "npm install",
         "bower install",
         "gulp clean",
         "gulp min"
      ]
   }
}

修改project.json后,出现这个错误:

Failed to make the following project runnable: MVC6_Full_Version (.NETCoreApp,Version=v1.0) reason: Expected coreclr library not found in package graph. Please try running dotnet restore again.



为了解决这个问题,我运行了 dotnet restore命令,但没有运气。

然后,我添加了这个块:
"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},

添加这个块后,我得到了一个不同的错误:

Code: NU1002 Description: The dependency Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1.



基本上,我想在我的应用程序中添加两个引用 - .NET Framework 4.6.1 和 ASP.NET Core 1.0。

如何解决此错误?

最佳答案

绝对可以使用 .NET Framework 或 .NET Core 构建 ASP.NET Core 项目。你真的很接近 - 只需要一些调整:

  • 删除 runtimes部分,除非您打算进行 native 编译(有点不寻常)
  • 将引用置于 Microsoft.NETCore.Appdependencies netcoreapp1.0里面的部分部分。我已经测试了以下更改并且它恢复和编译没有错误:

  • project.json
    ...
    
       "frameworks": {
          "net461": {
    
          },
          "netcoreapp1.0": {
             "dependencies": {
                "Microsoft.NETCore.App": {
                   "type": "platform",
                   "version": "1.0.0"
                }
             },
             "imports": [
                "dotnet5.6",
                "portable-net45+win8"
             ]
          }
       }
    
    Microsoft.NETCore.App仅 .NET Core 需要依赖项,将其添加到此处将确保在为该框架构建时可用。

    另外,commands部分已被弃用,可以删除。

    关于.net - 解决错误 "Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38572255/

    相关文章:

    c# - VB.NET 问题。林克支持?

    c# - 如何在 OnPost 之后将模型保留在我的 View 中?

    azure - logger.Log 语句在 Azure 门户中的什么位置?

    c# - 依赖注入(inject)到 {get;设置;} 属性

    c# - 如何配置 asp.net kestrel 以实现低延迟?

    .net - "Directory.Delete( "path", false )"是做什么的?

    c# - 无法编辑 DataGridView 单元格,验证事件集 e.Cancel = true

    c# - 如何替换 LinkedList 中的元素?

    caching - 在 ASP.NET 5 中缓存模式是否有任何指导

    ASP.NET Identity 版本 3 与 MVC 5?