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.
Yes, <ProductVersion>
is listed in a project file. It matches the Visual Studio version number.
<ProductVersion>
will give you the version of MSBuild that is running the build process.
Note that in VS 2010 the build process might be targeting either .Net 4.0 or 3.5 You need to consider carefully if your conditional compilation depends on the msbuild version itself or on the target framework of the build and the tools the build is using. If your condition is based on the target framework, use <TargetFrameworkVersion>
.
Of course, if your build also might be run under VS 2008, you need to support proper fallback if <TargetFrameworkVersion>
is missing.
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.
<ProductVersion>
is crud from old VS versions and isn't in newer project files. Ignore it completely.