开发者

How do I compile a project for both .Net 3.5 and 4 at the same time

I need to compile a project for both .Net 3.5 and .Net 4.0. What is the most low-friction way of doing 开发者_开发知识库this? If I reference this project from another assembly, how do I determine which runtime is being targeted? Or should I just reference binaries directly?


I do this simply by having two csproj files. Then I can set the version, references, build-symbols, etc easily. To avoid having to maintain the file list in both, I use a blanket include - i.e.

I have (in the secondary .csproj):

<Compile Include="..\TheMainProject\**\*.cs" />

This says "compile all .cs files in and under ..\TheMainProject".


You can leverage multi-targeting feature.

Basically you will end up with something like that:

<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<MSBuild Projects="@(ProjectsToBuild)" 
         Properties="TargetFrameworkVersion=$(CustomTargetFrameworkVersion)" />

See for more details:

  • Multi-Targeting : How does it work?
  • Using MSBuild to Target Specific .NET Framework Versions


why would you need that ?

With the post/pre build task you can run msbuild to target a different framework, see the argument "toolversion"

http://msdn.microsoft.com/en-us/library/ms164311.aspx

MSBuild.exe MyProject.proj /ToolsVersion:4.0

and have a look at

http://msdn.microsoft.com/en-us/library/ee395432.aspx

But still I don't see any situation where I'd need that.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜