从ASP.NET 5引用.NET 4.6项目会导致生成错误 [英] Referencing a .NET 4.6 project from ASP.NET 5 causes build error
问题描述
在我的ASP.NET 5 RC1项目(仅针对dnx46)中,我试图添加对目标为.net 4.6的(经典)类库项目的引用.
In my ASP.NET 5 RC1 project (targeting only dnx46) I'm trying to add a reference to a (classic) Class Library project targeting .net 4.6.
在构建时出现此错误: ... \ MSBuild \ 14.0 \ bin \ Microsoft.Common.CurrentVersion.targets(1819,5):警告MSB3274:无法针对主引用"... \ ClassLibrary1.dll"进行解析,因为它是针对.\ ClassLibrary1.dll"构建的. NETFramework,Version = v4.6框架.这是当前目标框架".NETFramework,Version = v4.5.1"的更高版本.
I get this error at build time: ...\MSBuild\14.0\bin\Microsoft.Common.CurrentVersion.targets(1819,5): warning MSB3274: The primary reference "...\ClassLibrary1.dll" could not be resolved because it was built against the ".NETFramework,Version=v4.6" framework. This is a higher version than the currently targeted framework ".NETFramework,Version=v4.5.1".
为什么会这样?我的ASP.NET 5项目没有针对4.5.1.根据project.json文件,它仅针对dnx46.我在任何地方都找不到.net 4.5.1的提法.
Why is this happening? My ASP.NET 5 project isn't targeting 4.5.1. According to the project.json file it's only targeting dnx46. I can't find any mention of .net 4.5.1 anywhere.
这是我的WebApplication项目的project.json:
Here's the project.json for my WebApplication project:
{
"version": "1.0.0-*",
"compilationOptions": {
"emitEntryPoint": true
},
"dependencies": {
"Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
"Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final"
},
"commands": {
"web": "Microsoft.AspNet.Server.Kestrel"
},
"frameworks": {
"dnx46": {
"dependencies": {
"ClassLibrary1": "1.0.0-*"
}
},
},
"exclude": [
"wwwroot",
"node_modules"
],
"publishExclude": [
"**.user",
"**.vspscc"
]
}
这是包装"过程为我的ClassLibrary项目创建的project.json:
And here's the project.json that the "wrapping" process creates for my ClassLibrary project:
{
"version": "1.0.0-*",
"frameworks": {
"net46": {
"wrappedProject": "../../ClassLibrary1/ClassLibrary1.csproj",
"bin": {
"assembly": "../../ClassLibrary1/obj/{configuration}/ClassLibrary1.dll",
"pdb": "../../ClassLibrary1/obj/{configuration}/ClassLibrary1.pdb"
}
}
}
}
推荐答案
如果使用VS 2015 Update 1进行构建,警告仍然存在,但Web应用程序运行良好,可以从.net4.6程序集中调用方法.
The warning is still there if built using VS 2015 Update 1, but web app works well and can call a method from .net4.6 assembly.
这篇关于从ASP.NET 5引用.NET 4.6项目会导致生成错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!