P
P
paz2013-05-16 09:26:02
.NET
paz, 2013-05-16 09:26:02

Build solutions under different frameworks

Hello. There is a big solution with a bunch of projects. There is a need to build it under 3.5 and under 4.5 without changing the code. Is there a way to do this in Visual Studio?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
SergeyGrigorev, 2013-05-16
@SergeyGrigorev

Try building via NAnt
nant.sourceforge.net/faq.html#change-targetframework

S
shai_hulud, 2013-05-16
@shai_hulud

it is quite possible to specify the framework in the build parameters:

%windir%\Microsoft.NET\Framework\v4.0.30319\msbuild.exe "c:\dev\MySolution.sln" /p:Configuration=RELEASE /p:TargetFrameworkVersion=v3.5

in the project, you can insert a couple of conditions on the version of the framework:
<PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v3.5' ">
    <DefineConstants>$(DefineConstants);NET35</DefineConstants>
  </PropertyGroup>
  <PropertyGroup Condition=" '$(TargetFrameworkVersion)' == 'v4.5' ">
    <DefineConstants>$(DefineConstants);NET45</DefineConstants>
  </PropertyGroup>

And then in the code you can fry the preprocessor:
#if NET45
    const int MagicNumber = 42;
#elseif NET35
    const int MagicNumber = -1;
#endif

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question