visual-studio-2010 - Visual Studio 2010:针对更高框架版本的引用程序集

标签 visual-studio-2010 reference assemblies

当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/

相关文章:

c# - 如何创建其他窗口继承的窗口?

c++ - 在 Visual Studio 中使用 C++/C# 连接 MySQL

c++ - 需要帮助创建数组并在另一个函数中编辑它并将其发送回初始函数

c# - Orchard : Full Source or Not?

visual-studio-2010 - 我安装的 Visual Studio 2010 Express 不包含 “redist” 文件夹

c++ - C++17 中结构化绑定(bind)引入的标识符有哪些类型?

mysql - 重置数据库无法删除或更新父行 : a foreign key constraint fails

C# 程序集,程序集中有什么?

.net - 如何构建/部署需要同一程序集的多个版本的项目?

wpf - 使用 Prism 时将应用程序的部分拆分为各自的程序集