Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
578 views
in Technique[技术] by (71.8m points)

Visual Studio 2010: Reference Assemblies Targeting Higher Framework Version

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 doesn't allow for this any more. The full issue is described on 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.

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)?

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

The exact error is:

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".

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Step1: Unload the referencing project targeting .NET 2.0

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

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>

Step4: Reload the project.

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.

Source: http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/dfadfb34-5328-4c53-8274-931c6ae00836


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...