14 May, 2011

Same codebase –> multiple .NET frameworks ?

Building a logger what I want to be available to both .NET 3.5 and .NET 4.0 clients, I do not want to have two copies of the same projects (one for 3.5 and one for 4.0). So what to do? How can you setup Visual Studio to build and emit code for respectively 3.5 and 4.0 all from the same code base?

The short answer is: You can not! You have to have a physical copy of the project for each version, unless you hand-fiddle with the project (.csproj) files ;-) In that case, Yes – we can (to quote some politician that I hold in very positive esteem).

Build for 2 frameworks...

How to do?

1) In Visual Studio – you set 2 new Configurations (‘3.5’ and ‘4.0’)

Settings dialog

2) Close the project

3) Open the project file (.csproj) in an external editor (e.g. Notepad++)

4) Locate the ‘<TargetFrameworkVersion>’ tag in the file in the first PropertyGroup!

csproj-file

5) Take out this element/tag and insert it into the two new PropertyGroups just created in step 1

csproj-file

6) Replace the text with respectively (one for each property group)
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion> <TargetFrameworkVersion>v4.0</TargetFrameworkVersion>

7) Close the file (.csproj) and re-open it in Visual Studio 2010

8) Now you can select the target configuration (3.5 or 4.0) and you will see an assembly built for the two different frameworks respectively

bin-folder

9) You are done!

 

Verification:
To verify that this actually works, open the files (dll) in Reflector and see the internal references

.NET 3.5 version     .NET 4.0 version

How clever is that?

2 comments:

Radley Co Tad said...

Hi, Great.. Tutorial is just awesome..It is really helpful for a newbie like me.. I am a regular follower of your blog. Really very informative post you shared here. Kindly keep blogging. If anyone wants to become a .Net developer learn from Dot Net Training in Chennai. or learn thru Dot Net Training in Chennai. Nowadays Dot Net has tons of job opportunities on various vertical industry.
or Javascript Training in Chennai. Nowadays JavaScript has tons of job opportunities on various vertical industry.

Pavel Co Ebele said...

Great Article
IEEE Final Year Projects for CSE
IEEE Project Centers in Chennai

iPhone/XCode - not all cases are equal!

This bit me! Having made some changes to an iPhone application (Obj-C); everything worked fine in the simulator. But, when deploying the s...