blog tag

Target Multiple Frameworks with MSBuild in csproj

Description: Target multiple .net frameworks with MSBuild in csproj
Publish Date: 05/04/2014
Keywords: MSBuild csproj target multiple .net framework visual studio C#

From 0 to 15 MPH with MSBuild.

Problem Scope:

For complicated and boring reasons I needed to target multiple .net frameworks that would continuously integrate with an existing build environment. This meant modifying my .csproj to target more than just my currently chosen framework. This does NOT cover using compiler directives to use features not available in all chosen frameworks.

!!Warning!! If you are really looking to do this you should definitely stop and answer the question Why. I'm not entirely sure that I'm doing it for the right reasons :).

Research:

Step 1: Google

Step 2: Stackoverflow

Solution:

This post was the front runner but I wish somebody had posted an actual project to play with since it took me so long to understand what was happening.

https://stackoverflow.com/questions/2923210/c-sharp-conditional-compilation-and-framework-targets/2928835#2928835

With the help of my work buddies I think I understand enough to travel at about 15mph down the MSBuild super highway of secret variables.

Here is a working VS2013 example with a console app.

 

My logging comments tell me that I have no idea what order this stuff is running. Comments?

Comments: 3
ozbob (02/17/2017)

I didn't find this worked for me. I combined this and https://social.msdn.microsoft.com/Forums/vstudio/en-US/cb69ad54-eebf-4f83-aa54-589005d53e85/building-multiple-projects-with-the-same-assembly-name-but-different-target-frameworks


ozbob (02/21/2017)

found an article supporting a similar but better approach: https://shazwazza.com/post/Multi-targeting-a-single-Net-project-to-build-for-different-framework-versions


Allan (02/21/2017)

Cool, thanks for the info.


© Chadwick 2021