I would like to have two different .net framework targets via configuration in Visual Studio 2015. While for references, you can edit the CSPROJ file and add a conditions, this does not seem to work for the TargetFrameworkVersion in the first PropertyGroup of the file. I have the impression that any Condition in that element causes VS to completely ignore this element and to fall back to the default value of "v4.0".
Is there any way I can get different target framework versions for different configurations?
This is what I tried in the CSPROJ file:
<Project ToolsVersion="14.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
...
<!-- this is what VS2015 would put into the file:
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
-->
<!-- this is what does not work: -->
<TargetFrameworkVersion Condition="'$(Configuration)' == 'OLD_Debug' OR '$(Configuration)' == 'OLD_Release'">v3.5</TargetFrameworkVersion>
<TargetFrameworkVersion Condition="'$(Configuration)' == 'NEW_Debug' OR '$(Configuration)' == 'NEW_Release'">v4.0</TargetFrameworkVersion>
...
</PropertyGroup>
...
</Project>
A similar approach with conditions for the assembly references works fine.
EDIT
I found a similar Stackoverflow question:
Targetting multiple .net framework versions by using different project configurations and tried the approach suggested in the non-accepted answer to remove the TargetFrameworkVersion from the first PropertyGroup block, and edit the later <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'OLD_Debug|AnyCPU' "> blocks to contain it, but my assembly is still compiled for framework 3.5 no matter which configuration I use. At least if I look at the assembly from Powershell using [System.Reflection.Assembly]::LoadFrom("C:\PATH\MyAssembly.dll").ImageRuntimeVersion, I always get version 2, not 4.
TargetFrameworkVersionas a parameter to MSBuild for each. Do note this can be accomplished far easier in Visual Studio 2017 with the new.csprojformat:<TargetFrameworks>net35;net45;netstandard2.0</TargetFrameworks>, which builds all versions in Visual Studio.