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).
How to do?
1) In Visual Studio – you set 2 new Configurations (‘3.5’ and ‘4.0’)
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!
5) Take out this element/tag and insert it into the two new PropertyGroups just created in step 1
6) Replace the text with respectively (one for each property group)
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
9) You are done!
To verify that this actually works, open the files (dll) in Reflector and see the internal references
How clever is that?