Visual Studio 2010:以更高的框架版本为目标的参考程序集 [英] Visual Studio 2010: Reference Assemblies Targeting Higher Framework Version

查看:101
本文介绍了Visual Studio 2010:以更高的框架版本为目标的参考程序集的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当A面向.NET 3.5而B面向.NET 2.0时,Visual Studio 2008确实允许您引用程序集B中的程序集A.

Visual Studio 2008 did let you reference an assembly A from an Assembly B when A was targeting .NET 3.5 and B was targeting .NET 2.0.

Visual Studio 2010不再允许这样做.有关完整问题,请参见 MSDN :

Visual Studio 2010 doesn't allow for this any more. The full issue is described on MSDN:

您可以创建用于以下目的的应用程序: 参考项目或程序集 针对.NET的不同版本 框架.例如,如果您创建 面向.NET的应用程序 框架4客户端配置文件 项目可以引用一个程序集,该程序集 针对.NET Framework 2.0版. 但是,如果您创建一个项目, 针对.NET的早期版本 框架,您不能设置 在该项目中引用一个项目 或以.NET为目标的程序集 Framework 4客户端配置文件或.NET 框架4 .为了消除错误, 确保配置文件定位为 您的应用程序与 项目针对的配置文件 或您引用的程序集 应用程序.

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(即允许引用针对更高框架版本的程序集)?

Is there any way I can get VS2010 to behave like VS2008 in this regard (i.e. allowing references to assemblies targeting higher framework versions)?

我知道VS 2010行为背后的原因以及需要注意的部署注意事项,无需重复.

I know the reasoning behind the VS 2010 behavior and the deployment considerations I need to be aware of, no need to repeat that.

确切的错误是:

警告MSB3268:主要参考 "xxx.dll" 无法解决,因为它有 对...的间接依赖 框架程序集"System.Core, 版本= 3.5.0.0,文化=中性, PublicKeyToken = b77a5c561934e089 目前无法解决 目标框架. ".NETFramework,Version = v2.0".到 解决此问题,删除 参考资料 "xxx.dll" 或将您的应用程序重新定位到 包含的框架版本 "System.Core,版本= 3.5.0.0, 文化=中立, PublicKeyToken = b77a5c561934e089".

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的引用项目

Step1: Unload the referencing project targeting .NET 2.0

Step2:右键单击已卸载的项目,然后从上下文菜单中选择编辑"

Step2: Right click the unloaded project and select edit from context menu

第3步:将<SpecificVersion>true</SpecificVersion>添加到参考中.以下是我的repro解决方案的示例:

Step3: Add <SpecificVersion>true</SpecificVersion> to the reference. Below is a sample from my repro solution:

<ProjectReference Include="..\HighFX\HighFX.csproj">
  <Project>{8DD71CAF-BEF7-40ED-9DD0-25033CD8009D}</Project>
  <Name>HighFX</Name>
  <SpecificVersion>true</SpecificVersion>
</ProjectReference>

第4步:重新加载项目.

Step4: Reload the project.

现在您应该可以在Visual Studio 2010中进行构建,仍然可能出现如下警告,但是构建可以成功.

Now your should be able to build within the Visual Studio 2010, there could still be a warning as below, but the build can be successful.

来源: http://social.msdn.microsoft.com/Forums/zh-CN/msbuild/thread/dfadfb34-5328-4c53-8274-931c6ae00836

这篇关于Visual Studio 2010:以更高的框架版本为目标的参考程序集的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆