Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In MSBuild is it possible to determine if I'm running in Visual Studio

Are the any MSBuild properties that Visual Studio sets? I'm looking to have some conditional behavior depending on the version (if any) of visual studio.

like image 668
Scott Weinstein Avatar asked Apr 28 '10 16:04

Scott Weinstein


People also ask

Is Visual Studio using MSBuild?

Visual Studio uses MSBuild, but MSBuild doesn't depend on Visual Studio. By invoking msbuild.exe on your project or solution file, you can orchestrate and build products in environments where Visual Studio isn't installed. Visual Studio uses MSBuild to load and build managed projects.

What is the difference between MSBuild and Visual Studio build?

Visual Studio determines the build order and calls into MSBuild separately (as needed), all completely under Visual Studio's control. Another difference arises when MSBuild is invoked with a solution file, MSBuild parses the solution file, creates a standard XML input file, evaluates it, and executes it as a project.

Is MSBuild a compiler?

MSBuild uses csc.exe as its actual compiler but knows where to find assemblies, references etc based on your solution and project files (these files are actually xml files). When using csc.exe you must manually provide paths to your files, references and so on, thus making your compilation much more difficult.


2 Answers

To directly address the question in your title - if you just want to know if you are being built from VS or not, check the value of IsDesktopBuild which will return true or false appropriately.

like image 38
AakashM Avatar answered Sep 19 '22 14:09

AakashM


The property value you should be using is BuildingInsideVisualStudio, when you are building inside of Visual Studio this property will be set to true. Since ProductVersion is declared in the project file you cannot use it because it will have the same value whether building inside of VS or via msbuild.exe.

<PropertyGroup>     <MyProp Condition=" '$(BuildingInsideVisualStudio)' == 'true' ">Foo</MyProp>       <MyProp Condition=" '$(BuildingInsideVisualStudio)' != 'true' ">Bar</MyProp>  </PropertyGroup> 
like image 90
Sayed Ibrahim Hashimi Avatar answered Sep 18 '22 14:09

Sayed Ibrahim Hashimi