[英]Solving error “Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1”
I have an ASP.NET Core 1.0 complete application running using net461
references. 我有一个使用
net461
引用运行的ASP.NET Core 1.0完整应用程序。 Now I am trying to add another framework - netcoreapp1.0
. 现在我想添加另一个框架
netcoreapp1.0
。 For this, I have updated my project.json like this: 为此,我更新了我的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"
]
}
}
After modifying project.json, I got this error: 修改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.
无法使以下项目可运行:MVC6_Full_Version(.NETCoreApp,Version = v1.0)原因:在包图中找不到预期的coreclr库。 Please try running dotnet restore again.
请尝试再次运行dotnet restore。
To resolve this, I ran dotnet restore
command but no luck. 要解决这个问题,我运行了
dotnet restore
命令,但没有运气。
Then, I added this block: 然后,我添加了这个块:
"Microsoft.NETCore.App": {
"version": "1.0.0",
"type": "platform"
},
After adding this block, I got a different error: 添加此块后,我得到一个不同的错误:
Code: NU1002 Description: The dependency Microsoft.NETCore.App 1.0.0 does not support framework .NETFramework,Version=v4.6.1.
代码:NU1002描述:依赖Microsoft.NETCore.App 1.0.0不支持框架.NETFramework,Version = v4.6.1。
Basically, I want to add both references in my applications - .NET Framework 4.6.1 and ASP.NET Core 1.0. 基本上,我想在我的应用程序中添加两个引用 - .NET Framework 4.6.1和ASP.NET Core 1.0。
How do I resolve this error? 我该如何解决这个错误?
It's definitely possible to build ASP.NET Core projects using .NET Framework or .NET Core. 使用.NET Framework或.NET Core构建ASP.NET Core项目绝对是可能的。 You're really close - just a few tweaks needed:
你真的很接近 - 只需要一些调整:
runtimes
section, unless you are intending to do native compilation (somewhat unusual) runtimes
部分,除非您打算进行本机编译(有点不寻常) Microsoft.NETCore.App
in a dependencies
section inside the netcoreapp1.0
section. Microsoft.NETCore.App
在dependencies
内部部分netcoreapp1.0
部分。 I've tested the following change and it restores and compiles without errors: project.json project.json
...
"frameworks": {
"net461": {
},
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": {
"type": "platform",
"version": "1.0.0"
}
},
"imports": [
"dotnet5.6",
"portable-net45+win8"
]
}
}
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. Microsoft.NETCore.App
.NETCore.App依赖关系仅对.NET Core是必需的,在此处添加它将确保在为该框架构建时可用。
Also, the commands
section has been deprecated and can be removed. 此外,
commands
部分已被弃用,可以删除。
I referenced .net core class library in .net 4.6.1 by changing the following. 我通过更改以下内容引用.net 4.6.1中的.net核心类库。
Before I was getting this error when trying to reference the .net core from .net 4.6.1 在尝试从.net 4.6.1引用.net核心时出现此错误之前
Fix: 固定:
Original 原版的
{
"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" ]
}
}
Corrected 更正
{
"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" ]
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.