I have a class library that targets .NET 3.5. Now, I would like to add some features that require .NET 4.0, but I still want to be able to generate a version that targets .NET 3.5 (without these features of course).
Ideally, I would like to target a different framework version based on the configuration:
- Debug, Release => .NET 3.5
- Debug 4.0, Release 4.0 => .NET 4.0
Unfortunately it doesn't seem to be possible, as the target framework is global for the whole project...
Is there a way around it? I know I could create a second project that includes the same files, but it's pretty bad for maintainability....
What is the easiest way to do this? If you have ever done something similar, which approach worked best?
First of all, you could start off by creating a conditional compilation symbol that enables you to include or exclude the extra features that are only available for the .NET4.0 framework.
Next to that, I think you'll have to use MSBuild directly, instead of letting VS.NET build your project. I've done something similar once. In short, it comes down to the fact that you'll have to create 2 build tasks within your MSbuild script. One that allows you to build your project for .NET 3.5, and one that allows you to build the project targetting .NET 4.0.
In each build-task, you can define the target framework, and the conditional compilation symbol that you'd want to use.
The build - tasks in your build-script could like like this:
Offcourse, when you'd want to build for the 2 versions, you'll have to execute each msbuild command separatly on the command line.