无法解析主要引用,因为它是针对比当前目标框架更高版本的 .NET 框架构建的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18360561/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
The primary reference could not be resolved because it was built against a higher version of the .NET framework than the currently targeted framework
提问by Dude0001
I am trying to build a project that references a 3rd party SlingshotClient.dll. The project builds fine on other developers workstations. However, I am getting the error below. One difference that I could imagine is contributing to my issue is that I also have VS 2012 and .NET Frameworks 4.5 installed on my machine. I believe the other developers that can build this successfully, don't have those installed.
我正在尝试构建一个引用 3rd 方 SlingshotClient.dll 的项目。该项目在其他开发人员工作站上构建良好。但是,我收到以下错误。我可以想象的一个不同之处是导致我的问题,我的机器上还安装了 VS 2012 和 .NET Frameworks 4.5。我相信可以成功构建它的其他开发人员没有安装这些。
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5): warning MSB3274: The primary reference "SlingshotClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb5a8745472e181a, processorArchitecture=MSIL" could not be resolved because it was built against the ".NETFramework,Version=v4.5" framework. This is a higher versio n than the currently targeted framework ".NETFramework,Version=v4.0".
C:\Windows\Microsoft.NET\Framework\v4.0.30319\Microsoft.Common.targets(1578,5):警告 MSB3274:主要参考“SlingshotClient, Version=1.0.0.0, Culture=neutral, PublicKeyToken=bb5a8745472e181a, processorArchitecture =MSIL”无法解析,因为它是针对“.NETFramework,Version=v4.5”框架构建的。这是比当前目标框架“.NETFramework,Version=v4.0”更高的版本。
The error seems to be saying that our project targets the framework version 4.0 (which is correct), but the referenced SlingshotClient.dll was built targeting framework version 4.5. When I look at the SlingshotClient.dll in the dissembler, it looks to me that the assembly was built targeting framework version 4.0
错误似乎是说我们的项目针对框架版本 4.0(这是正确的),但引用的 SlingshotClient.dll 是针对框架版本 4.5 构建的。当我查看反汇编程序中的 SlingshotClient.dll 时,在我看来该程序集是针对框架版本 4.0 构建的


回答by Dude0001
Apparently if you have only .NET Frameworks 4.0 installed, you can add as a reference a .NET assembly that targets 4.5 to a project that targets .NET 4.0. This will compile and run with no errors.
显然,如果您只安装了 .NET Frameworks 4.0,您可以将面向 4.5 的 .NET 程序集作为参考添加到面向 .NET 4.0 的项目。这将编译并运行,没有错误。
As soon as you install .NET Frameworks 4.5, compile will fail. The solution is to target your project for .NET Framework 4.5 or get a version of the referenced assembly that targets .NET 4.0.
一旦安装 .NET Frameworks 4.5,编译就会失败。解决方案是将您的项目定位为 .NET Framework 4.5 或获取一个以 .NET 4.0 为目标的引用程序集版本。
.NET 4.5 is a drop in replacement for 4.0. 4.0 doesn't know anything about 4.5, and I assume it is just looking at the first digit of the version number which for 4.0 or 4.5 is the same, so it is allowed to compile. As soon as you install 4.5, your 4.0 projects are compiled using the 4.5 Frameworks and it now knows about 4.5 and complains.
.NET 4.5 是 4.0 的替代品。4.0 对 4.5 一无所知,我认为它只是查看 4.0 或 4.5 版本号的第一个数字,因此允许编译。安装 4.5 后,您的 4.0 项目将使用 4.5 框架编译,现在它知道 4.5 并抱怨。

