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

倖福魔咒の 提交于 2019-12-21 09:36:37

问题


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?


回答1:


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




回答2:


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



回答3:


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.



来源:https://stackoverflow.com/questions/7074946/how-do-i-compile-a-project-for-both-net-3-5-and-4-at-the-same-time

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!