Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Override target framework from command line

Tags:

I want to build a c# project(.csproj) from commandline using msbuild and want to target .Net2.0 runtime.

I see that the project xml file has 2 tags of interest

<Project ToolsVersion="4.0" ...  

and

<TargetFrameworkVersion>v2.0</TargetFrameworkVersion> 

I was wondering if

  • Can ToolsVersion 4.0 produce compatible code for .Net2.0 runtime?
  • Can I override the target framework tag from the project file via the command line (does the /ToolsVersion command line switch achieve this?

I specifically want to achieve this via command line and not modify the project file.

Currently I am doing something like this

msbuild myproj.csproj /p:Configuration=Release 
like image 231
Kevin Boyd Avatar asked Aug 17 '12 09:08

Kevin Boyd


People also ask

What does Targetframework mean?

A project can be built to run on a target framework, which is a particular version of the . NET Framework, and a target platform, which is a particular software architecture. For example, you can target an application to run on the .

How use MSBuild command line?

To run MSBuild at a command prompt, pass a project file to MSBuild.exe, together with the appropriate command-line options. Command-line options let you set properties, execute specific targets, and set other options that control the build process.


1 Answers

You need the commandline arguments for msbuild to make that work:

msbuild.exe MyProj.proj /p:TargetFrameworkVersion=v2.0;Configuration=Release /tv:3.5 

therfore overriding the value in the proj file aswell as the ToolsVersion.

To find out which msbuild version default is used, start a Visual Studio Command prompt ( found in the Start menu > Microsoft Visual studio 2010 > Visual Studio Tools) and type msbuild. The first line of the output will hold your BuidEngineversion:

Microsoft (R) Build Engine Version 4.0.30319.1

From the msdn doc:

MSBuild uses a tool set of tasks, targets, and tools to build an application. Typically, a MSBuild tool set includes a microsoft.common.tasks file, a microsoft.common.targets file, and compilers such as csc.exe and vbc.exe. Most tool sets can be used to compile applications to more than one version of the .NET Framework and more than one system platform

You could also check the Environment vars for a version of the framework installed: set F from the Visual Studio Command prompt gives me this result:

Framework35Version=v3.5
FrameworkDir=c:\Windows\Microsoft.NET\Framework\
FrameworkDIR32=c:\Windows\Microsoft.NET\Framework\
FrameworkVersion=v4.0.30319
FrameworkVersion32=v4.0.30319

ToolSet Explanation
ToolSetVersion

like image 59
rene Avatar answered Oct 09 '22 17:10

rene