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.
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.
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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With