当A面向.NET 3.5而B面向.NET 2.0时,Visual Studio 2008确实允许您从Assembly A
中引用Assembly B
。
Visual Studio 2010不再允许这样做。完整问题在MSDN上描述:
You can create applications that reference projects or assemblies that target different versions of the .NET Framework. For example, if you create an application that targets the .NET Framework 4 Client Profile, that project can reference an assembly that targets .NET Framework version 2.0. However, if you create a project that targets an earlier version of the .NET Framework, you cannot set a reference in that project to a project or assembly that targets the .NET Framework 4 Client Profile or the .NET Framework 4. To eliminate the error, make sure that the profile targeted by your application is compatible with the profile targeted by the projects or assemblies referenced by your application.
在这方面,有什么方法可以使VS2010表现得像VS2008(即允许引用针对更高框架版本的程序集)?
我知道VS 2010行为背后的原因以及我需要了解的部署注意事项,无需重复。
确切的错误是:
warning MSB3268: The primary reference "xxx.dll" could not be resolved because it has an indirect dependency on the framework assembly "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" which could not be resolved in the currently targeted framework. ".NETFramework,Version=v2.0". To resolve this problem, either remove the reference "xxx.dll" or retarget your application to a framework version which contains "System.Core, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089".
最佳答案
步骤1:卸载针对.NET 2.0的引用项目
步骤2:右键单击已卸载的项目,然后从上下文菜单中选择“编辑”
步骤3:将<SpecificVersion>true</SpecificVersion>
添加到引用中。以下是我的repro解决方案的示例:
<ProjectReference Include="..\HighFX\HighFX.csproj">
<Project>{8DD71CAF-BEF7-40ED-9DD0-25033CD8009D}</Project>
<Name>HighFX</Name>
<SpecificVersion>true</SpecificVersion>
</ProjectReference>
步骤4:重新载入项目。
现在您应该可以在Visual Studio 2010中进行构建了,仍然可能出现如下警告,但是构建可以成功。
资料来源:http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/dfadfb34-5328-4c53-8274-931c6ae00836
关于visual-studio-2010 - Visual Studio 2010:针对更高框架版本的引用程序集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3298577/