解决错误“ Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version = v4.6.1”。 [英] Solving error "Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1"
问题描述
我有一个使用 net461
引用运行的ASP.NET Core 1.0完整应用程序。现在,我试图添加另一个框架- netcoreapp1.0
。为此,我像这样更新了我的project.json:
I have an ASP.NET Core 1.0 complete application running using net461
references. Now I am trying to add another framework - netcoreapp1.0
. For this, I have updated my project.json like this:
{
"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后,出现此错误:
After modifying project.json, I got this error:
无法使以下项目可运行:MVC6_Full_Version
(.NETCoreApp,Version = v1.0)原因:预期在包图中找不到coreclr库
。请尝试再次运行dotnet restore。
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
To resolve this, I ran dotnet restore
command but no luck.
然后,我添加了这个代码段:
Then, I added this block:
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
添加此块后,我遇到了另一个错误:
After adding this block, I got a different error:
代码:NU1002说明:依赖项Microsoft.NETCore.App 1.0.0
不支持框架.NETFramework,Version = v4.6.1。
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。
Basically, I want to add both references in my applications - .NET Framework 4.6.1 and ASP.NET Core 1.0.
如何我该解决这个错误吗?
How do I resolve this error?
推荐答案
使用.NET Framework或.NET Core绝对可以构建ASP.NET Core项目。您真的很接近-只需进行一些调整:
It's definitely possible to build ASP.NET Core projects using .NET Framework or .NET Core. You're really close - just a few tweaks needed:
- 删除
运行时
部分,除非您打算进行本机编译(有点不寻常) - 将对
Microsoft.NETCore.App
的引用放在dependencies
部分 inside 中的部分。我已经测试了以下更改,并且可以无错误地恢复和编译:
- Remove the
runtimes
section, unless you are intending to do native compilation (somewhat unusual) - Place the reference to
Microsoft.NETCore.App
in adependencies
section inside thenetcoreapp1.0
section. I've tested the following change and it restores and compiles without errors:
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所必需的,在此处添加它将确保在为该框架构建时可用。
The Microsoft.NETCore.App
dependency is only required for .NET Core, and adding it here will make sure it's available when building for that framework.
此外,命令
部分已被弃用,可以删除。
Also, the commands
section has been deprecated and can be removed.
这篇关于解决错误“ Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version = v4.6.1”。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!