I am building my solutions using MsBuild in a batch file as follows:
@echo off
set msBuildExe="C:\Windows\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe"
set solutionsFile="C:\TestProject\mySln.sln"
rem Build the solutions:
%msBuildExe% /t:Build /p:Configuration=Release /p:Platform=x64 %solutionsFile%
Problem is that I have Multiple Versions of Visual Studio installed and I want to point MsBuild.exe to use the compiler of VS2017.
How can I do that?
According to the Visual Studio Blog MSBuild is now part of Visual Studio!:
We could to know the MSBuild ships as a part of Visual Studio instead of the .NET Framework. So, if you want to use Visual Studio 2017 compiler, you need to use the MSBuild from the Visual Studio 2017:
Path: C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\MSBuild.exe
Besides, you can also use the
VsDevCmd.bat
file to set the build environment, just like stijn said, if you execute that file, you do not need to specify the MSBuild path, you can execute MSBuild.exe directly.Check the similar thread for some details.
Hope this helps.
You need two seperate things here: msbuild, to drive the build process, and the compiler/linker/... to perform the actual build phases. These are actually orthogonal (theoretically, not sure how far it goes in practice): msbuild which comes with VS2017 can be used to build a project using the compiler/linker from VS2013, as long as the environment is setup for those. So what you really need here is that last thing: you probably don't care what version of msbuild is used exactly, you want the correct C++/C# toolsets used.
The canonical way to do that is to run the .bat files supplied with each version of VS, accessible from the start menu as 'Developer Command Prompt'. That will also setup the path to msbuild so you don't need to hardocde that. (note these batchfiles also have arguments allowing to select different versions of toolsets etc but that's out of scope for this question)
Example for VS2017, no hardocded paths so should be reusable accross machines and enterprise/community/...:
This should get you where your going
What's new in MSBuild 15
Changed path