Earlier versions of MSBuild could be found here: %programfiles(x86)%\\msbuild\\
But for Visual Studio 2017RC the path
Now that VS 2017 has been released, thought it might be useful to add my 2 cents:
Creating a batch file:
Open Notepad
Copy the following and paste into notepad, replacing the solution you want to build with [My Solution Name Here]:
@echo off
:variables
SET msBuildLocation="C:\Program Files (x86)\Microsoft Visual Studio\2017\Community\MSBuild\15.0\Bin\msbuild.exe"
SET solutionDirectory=[My Solution Location Here]
SET batchFileLocation=[BatchFileLocation Here]
cd %solutionDirectory%
echo Building MS files for [My Solution Name Here].
call %msBuildLocation% [My Solution Name].sln /p:Configuration=Debug /m:4 /v:M /fl /flp:LogFile=msbuild.log;Verbosity=Normal /nr:false /consoleloggerparameters:Summary;ShowTimestamp;ShowEventId;PerformanceSummary
echo -
echo --------Done building [My solution name here].--------------
echo -
cd %batchFileLocation%
Save your batch file as whatever you want with the .bat extension. Be sure to select all files instead of .txt or else it won't work. Call the batch file by issuing the cd command where you have it saved at, and it should work. Or, just double-click. Done.
Please note that my version of visual studio is community; you'll need to replace the path with the appropriate version.
I also run the build tools from a bat file on my CI server: The new location I've found is this:
%programfiles(x86)%\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe
Microsoft have created a tool to find the location of Visual Studio 2017 and newer https://github.com/Microsoft/vswhere
That option and newer are decribed in this blog post.
If you have installed the .NET Core tools preview 3 or later, the dotnet
CLI should be available on the %PATH%
by default (even if you're not building a .NET Core project), so you could try dotnet msbuild
. Ref https://github.com/dotnet/docs/blob/master/docs/core/preview3/tools/dotnet-msbuild.md
I maintain a very simple PowerShell script (gist) to run CI/CLI builds with properly configured Visual Studio environment variables. It uses vswhere.exe
and VsDevCmd.bat
. It works well on build agents as a part of Azure DevOps pipelines. Particularly for C++ projects, it's vital to set INCLUDE
and LIB
properly, that's what VsDevCmd.bat
does.
E.g, run a build with MSBuild
for the solution in the current folder:
powershell -f _invoke-build.ps1 -buildCommand "msbuild ."
Copy VS' INCLUDE
environment variable into clipboard (for fun):
powershell -f _invoke-build.ps1 -buildCommand "set INCLUDE | clip"
The current version of the script:
<#
.Synopsis
Find Visual Studio and run its VsDevCmd.bat, then run a build command.
.Example
powershell -f _invoke-build.ps1 -buildCommand "msbuild ."
.Link
https://gist.github.com/noseratio/843bb4d9c410c42081fac9d8b7a33b5e
#>
#Requires -Version 5.0
# by @noseratio
param([Parameter(Mandatory = $true)] [string] $buildCommand)
Set-StrictMode -Version Latest
$ErrorActionPreference = 'Stop'
echo "Building via '$buildCommand' ..."
$vs_not_found = "Visual Studio hasn't been detected!"
$vswhere = "${env:ProgramFiles(x86)}/Microsoft Visual Studio/Installer/vswhere.exe"
if (!(Test-Path $vswhere)) { throw $vs_not_found }
$vs_ide_path = $(& $vswhere -format value -property productPath)
if (!(Test-Path $vs_ide_path)) { throw $vs_not_found }
$vs_ide_folder = "$(Split-Path $vs_ide_path)"
$vs_dev_cmd = "$vs_ide_folder/../Tools/VsDevCmd.bat"
$invoke = "call ""$vs_dev_cmd"" && cd ""$pwd"" && $buildCommand"
# we need to run via CMD for proper propagation of Visual Studio environment vars
& $env:comspec /s /c ""$invoke""
if (!$?) { throw "Failed with error code: $LastExitCode" }
Simplest way...
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe