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

查看:32
本文介绍了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 Client Profile 或 .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,版本 = 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".

推荐答案

Step1:卸载面向 .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

Step3:在引用中添加true.以下是我的重现解决方案的示例:

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

<ProjectReference Include="..HighFXHighFX.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/en-US/msbuild/thread/dfadfb34-5328-4c53-8274-931c6ae00836

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

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