Dmitri Nesteruk
Dmitri Nesteruk

Reputation: 23798

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?

Upvotes: 9

Views: 1963

Answers (3)

sll
sll

Reputation: 62564

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:

Upvotes: 2

remi bourgarel
remi bourgarel

Reputation: 9389

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.

Upvotes: 1

Marc Gravell
Marc Gravell

Reputation: 1064204

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

Upvotes: 9

Related Questions