I would like to target both .NET 3.5 and .NET 4.0 in my Visual Studio 2010 solution.
I am aware that I can set the <TargetFrameworkVersion />
in my project files, however this requires me to edit every project file before building the solution for a specific .NET framework version. Scott Dorman provides a macro which does the trick on his blog post Visual Studio 2010 and Target Framework Version.
I am looking for a global solution where I don't have to change the setting in every project. Is it possible to change a central setting at the solution level to achieve the same thing?
Not that I'm aware of.
Note that a project can be part of multiple solutions - or can be built independently of any solution. Thus all a "solution level" option could really do would be to set the default when creating a new project.
If you hand-edit the project files, I believe you should be able to create a single project file with configurations for .NET 3.5 and .NET 4. (I've certainly done that for .NET 2 and .NET 3.5 before now.) Then you could have different solution-level configurations which target the relevant project-level configurations.
As Jon Skeet wrote, there is no apparent way to define the target framework at the solution level. However, this can be done by adding specific configurations to the solution, then editing the
*.csproj
files manually to specify the targets for every configuration, rather than globally for the whole project.Here is a step-by-step guide:
Debug v3.5
) based on whatever existing settings you already have.<PropertyGroup>
element which matches the configuration you have just created (for instanceDebug v3.5|AnyCPU
).</PlatformTarget>
element, the<TargetFrameworkVersion>
and<TargetFrameworkProfile>
you need.Here is a sample:
Note that I also define the symbol
DOTNET35
, which allows me to write framework dependent#if
statements in the source code. I had, for instance, a few pieces of code which relied onSystem.Tuple
and by adding a minimalistic version of the class, I could back-port my .NET 4.0 application to .NET 3.5.Here is my snippet: