it-swarm.dev

解决错误“Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version = v4.6.1”

我有一个使用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后,我收到此错误:

无法使以下项目可运行:MVC6_Full_Version(.NETCoreApp,Version = v1.0)原因:在包图中找不到预期的coreclr库。请尝试再次运行dotnet restore。

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

然后,我添加了这个块:

"Microsoft.NETCore.App": {
  "version": "1.0.0",
  "type": "platform"
},

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

代码:NU1002描述:依赖Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version = v4.6.1。

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

我该如何解决这个错误?

13
Sachin411

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

  • 删除runtimes部分,除非您打算进行本机编译(有点不寻常)
  • Microsoft.NETCore.App的引用放在dependencies部分 inside netcoreapp1.0部分中。我测试了以下更改,它可以无错误地恢复和编译:

project.json

...

   "frameworks": {
      "net461": {

      },
      "netcoreapp1.0": {
         "dependencies": {
            "Microsoft.NETCore.App": {
               "type": "platform",
               "version": "1.0.0"
            }
         },
         "imports": [
            "dotnet5.6",
            "portable-net45+win8"
         ]
      }
   }

只有.NET Core需要Microsoft.NETCore.App依赖项,并且在此处添加它将确保在为该框架构建时可用。

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

12
Nate Barbettini

我通过更改以下内容引用.net 4.6.1中的.net核心类库。

在尝试从.net 4.6.1 引用.net内核时出现此错误之前 enter image description here

固定:

原版的

    {
    "dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    },
    "Interop.SHDocVw.dll": "1.1.0",
    "Microsoft.mshtml.dll": "7.0.3300.1"
    },

    "frameworks": {
    //"net461": {},
    "netcoreapp1.0": {
      "imports": [
        "dotnet5.6",
        "portable-net45+win8",
        "net461"
      ]
    }
   },

    "scripts": {
    "prepublish": [ "bower install", "dotnet bundle" ]
    }
   }

更正

    {
     "dependencies": {
        "Interop.SHDocVw.dll": "1.1.0",
        "Microsoft.mshtml.dll": "7.0.3300.1"
     },

    "frameworks": {
        "net461": {
        },
        "netcoreapp1.0": {
        "dependencies": {
            "Microsoft.NETCore.App": {
            "type": "platform",
            "version": "1.0.0"
            }
        },
        "imports": [
            "dotnet5.6",
            "portable-net45+win8",
            "net461"
        ]
        }
    },

    "scripts": {
        "prepublish": [ "bower install", "dotnet bundle" ]
    }
}
1
chdev77