Path to MSBuild
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty height:90px;width:728px;box-sizing:border-box;
How can I programatically get the path to MSBuild from a machine where my .exe is running?
I can get the .NET version from the Environment but is there a way of getting the correct folder for a .NET version?
.net msbuild
add a comment |
How can I programatically get the path to MSBuild from a machine where my .exe is running?
I can get the .NET version from the Environment but is there a way of getting the correct folder for a .NET version?
.net msbuild
add a comment |
How can I programatically get the path to MSBuild from a machine where my .exe is running?
I can get the .NET version from the Environment but is there a way of getting the correct folder for a .NET version?
.net msbuild
How can I programatically get the path to MSBuild from a machine where my .exe is running?
I can get the .NET version from the Environment but is there a way of getting the correct folder for a .NET version?
.net msbuild
.net msbuild
edited May 22 '13 at 20:33
Lukasz Lysik
8,50934267
8,50934267
asked Nov 29 '08 at 21:12
dagda1dagda1
8,40132133270
8,40132133270
add a comment |
add a comment |
18 Answers
18
active
oldest
votes
Poking around the registry, it looks like
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
may be what you're after; fire up regedit.exe and have a look.
Query via command line (per Nikolay Botev)
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
Query via PowerShell (per MovGP0)
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
4
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
6
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
2
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
6
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
2
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
|
show 3 more comments
You can also print the path of MSBuild.exe to the command line:
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
1
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
2
@VictorIonescu: You can use/reg:32
or/reg:64
on both bitnessess ofcmd
(or whatever process you are running) to explicitly get that path.
– Simon Buchan
Apr 20 '16 at 1:53
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
add a comment |
If you want to use MSBuild for .Net 4 then you can use the following PowerShell command to get the executable's path. If you want version 2.0 or 3.5 then just change the $dotNetVersion variable.
To run the executable you'll need to prepend the $msbuild variable with &. That will execute the variable.
# valid versions are [2.0, 3.5, 4.0]
$dotNetVersion = "4.0"
$regKey = "HKLM:softwareMicrosoftMSBuildToolsVersions$dotNetVersion"
$regProperty = "MSBuildToolsPath"
$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"
&$msbuildExe
2
works also for$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)
– Julian
Nov 10 '16 at 11:12
3
Does not work for VS 2017, which does not add a value under theHKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir fromHKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then appendMSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.
– Ian Kemp
May 11 '17 at 10:59
add a comment |
For cmd shell scripting in Windows 7, I use the following fragment in my batch file to find MSBuild.exe in the .NET Framework version 4. I assume version 4 is present, but don't assume the sub-version. This isn't totally general-purpose, but for quick scripts it may be helpful:
set msbuild.exe=
for /D %%D in (%SYSTEMROOT%Microsoft.NETFrameworkv4*) do set msbuild.exe=%%DMSBuild.exe
For my uses I'm exiting the batch file with an error if that didn't work:
if not defined msbuild.exe echo error: can't find MSBuild.exe & goto :eof
if not exist "%msbuild.exe%" echo error: %msbuild.exe%: not found & goto :eof
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
@yoyo What'sset bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?
– Elisée
May 17 '16 at 11:16
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
add a comment |
You can use this very trial PowerShell Command to get the MSBuildToolsPath
from the registry.
PowerShell (from registry)
Resolve-Path HKLM:SOFTWAREMicrosoftMSBuildToolsVersions* |
Get-ItemProperty -Name MSBuildToolsPath
Output
MSBuildToolsPath : C:Program Files (x86)MSBuild12.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions12.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 12.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:Program Files (x86)MSBuild14.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions14.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 14.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v2.0.50727
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 2.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v3.5
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 3.5
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v4.0.30319
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 4.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
or from the filesystem
PowerShell (from file system)
Resolve-Path "C:Program Files (x86)MSBuild*Binamd64MSBuild.exe"
Resolve-Path "C:Program Files (x86)MSBuild*BinMSBuild.exe"
Output
Path
----
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild12.0BinMSBuild.exe
C:Program Files (x86)MSBuild14.0BinMSBuild.exe
1
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
add a comment |
@AllenSanborn has a great powershell version, but some folks have a requirement to use only batch scripts for builds.
This is an applied version of what @bono8106 answered.
msbuildpath.bat
@echo off
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath > nul 2>&1
if ERRORLEVEL 1 goto MissingMSBuildRegistry
for /f "skip=2 tokens=2,*" %%A in ('reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath') do SET "MSBUILDDIR=%%B"
IF NOT EXIST "%MSBUILDDIR%" goto MissingMSBuildToolsPath
IF NOT EXIST "%MSBUILDDIR%msbuild.exe" goto MissingMSBuildExe
exit /b 0
goto:eof
::ERRORS
::---------------------
:MissingMSBuildRegistry
echo Cannot obtain path to MSBuild tools from registry
goto:eof
:MissingMSBuildToolsPath
echo The MSBuild tools path from the registry '%MSBUILDDIR%' does not exist
goto:eof
:MissingMSBuildExe
echo The MSBuild executable could not be found at '%MSBUILDDIR%'
goto:eof
build.bat
@echo off
call msbuildpath.bat
"%MSBUILDDIR%msbuild.exe" foo.csproj /p:Configuration=Release
For Visual Studio 2017 / MSBuild 15, Aziz Atif (the guy who wrote Elmah) wrote a batch script
build.cmd Release Foo.csproj
https://github.com/linqpadless/LinqPadless/blob/master/build.cmd
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :restore
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
nuget restore ^
&& call :build Debug %* ^
&& call :build Release %*
popd
goto :EOF
:build
setlocal
"%MSBUILD%" /p:Configuration=%1 /v:m %2 %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
2
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
1
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
2
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
add a comment |
The Registry locations
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
give the location for the executable.
But if you need the location where to save the Task extensions, it's on
%ProgramFiles%MSBuild
4
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
add a comment |
This works for Visual Studio 2015 and 2017:
function Get-MSBuild-Path
$vs14key = "HKLM:SOFTWAREMicrosoftMSBuildToolsVersions14.0"
$vs15key = "HKLM:SOFTWAREwow6432nodeMicrosoftVisualStudioSxSVS7"
$msbuildPath = ""
if (Test-Path $vs14key)
$key = Get-ItemProperty $vs14key
$subkey = $key.MSBuildToolsPath
if ($subkey)
$msbuildPath = Join-Path $subkey "msbuild.exe"
if (Test-Path $vs15key)
$key = Get-ItemProperty $vs15key
$subkey = $key."15.0"
if ($subkey)
$msbuildPath = Join-Path $subkey "MSBuild15.0binamd64msbuild.exe"
return $msbuildPath
3
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
3
For Build Tools, usevswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.
– TN.
May 17 '17 at 15:53
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
add a comment |
easiest way might be to open PowerShell and enter
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
add a comment |
On Windows 2003 and later, type this command in cmd:
cmd> where MSBuild
Sample result: C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
If nothing appears, it means that .NET framework is not included in the system PATH. The MSBuild should be in the .NET installation folder, along with .NET compilers (vbc.exe, csc.exe)
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
add a comment |
Starting with MSBuild 2017 (v15), MSBuild is now installed in a folder under each version of Visual Studio
Here are some examples of where MSBuild.exe is found on my machine:
C:windowsMicrosoft.NETFrameworkv2.0.50727MSBuild.exe (v2.0.50727.8745 32-bit)
C:windowsMicrosoft.NETFramework64v2.0.50727MSBuild.exe (v2.0.50727.8745 64-bit)
C:WindowsMicrosoft.NETFrameworkv3.5MSBuild.exe (v3.5.30729.8763 32-bit)
C:WindowsMicrosoft.NETFramework64v3.5MSBuild.exe (v3.5.30729.8763 64-bit)
C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe (v4.7.2053.0 32-bit)
C:WindowsMicrosoft.NETFramework64v4.0.30319MSBuild.exe (v4.7.2053.0 64-bit)
C:Program Files (x86)MSBuild12.0BinMSBuild.exe (v12.0.21005.1 32-bit)
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe (v12.0.21005.1 64-bit)
C:Program Files (x86)MSBuild14.0BinMSBuild.exe (v14.0.25420.1 32-bit)
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe (v14.0.25420.1 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe (v15.1.1012+g251a9aec17 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binamd64MSBuild.exe (v15.1.1012+g251a9aec17 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinMSBuild.exe (v15.1.1012.6693 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinamd64MSBuild.exe (v15.1.1012.6693 64-bit)
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
add a comment |
To retrieve path of msbuild 15 (Visual Studio 2017) with batch from registry w/o additional tools:
set regKey=HKLMSOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS7
set regValue=15.0
for /f "skip=2 tokens=3,*" %%A in ('reg.exe query %regKey% /v %regValue% 2^>nul') do (
set vs17path=%%A %%B
)
set msbuild15path = %vs17path%MSBuild15.0BinMSBuild.exe
Better available tools:
vswhere: Locate Visual Studio 2017 and newer installations, see get msbuild15 path with batch (uses hardcoded path as my snippet above).
Visual Studio Setup PowerShell Module by using Microsoft.VisualStudio.Workload.MSBuildTools
1
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
1
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
add a comment |
As of Visual Studio 2017, the "correct" way to do this is by invoking %ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe
and appending the hardcoded path MSBuild15.0BinMSBuild.exe
to the output, as per Microsoft's official wiki article.
Yes, it's even worse than reading the Registry directly, which I didn't think was possible - but Microsoft finds a way.
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
add a comment |
An one-liner based on @dh_cgn's answer:
(Resolve-Path ([io.path]::combine($env:ProgramFiles(x86), 'Microsoft Visual Studio', '*', '*', 'MSBuild', '*' , 'bin' , 'msbuild.exe'))).Path
It selects all existing paths paths of eg. C:Program Files (x86)Microsoft Visual Studio**MSBuild*binmsbuild.exe
.
The wildcards stars are:
- the year (2017)
- the visual studio edition (community, professional, enterprise)
- the tools version (15.0)
Be aware that this command is selecting the first path that matches the expression ordered by alphabet. To narrow it down just replace the wildcards with specific elements eg. the year or tools version.
add a comment |
For Visual Studio 2017 without knowing the exact edition you could use this in a batch script:
FOR /F "tokens=* USEBACKQ" %%F IN (`where /r "%PROGRAMFILES(x86)%Microsoft Visual
Studio2017" msbuild.exe ^| findstr /v /i "amd64"`) DO (SET msbuildpath=%%F)
The findstr command is to ignore certain msbuild executables (in this example the amd64).
add a comment |
add vswhere branch for https://github.com/linqpadless/LinqPadless/blob/master/build.cmd, works fine in my computer, and the vswhere branch works on my mate's computer.
May be, the vswhere branch should move forward as the first check.
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :build
for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe" -latest -requires Microsoft.Component.MSBuild`) do (
if /i "%%i"=="installationPath" set InstallDir=%%j
)
if exist "%InstallDir%MSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%InstallDir%MSBuild15.0BinMSBuild.exe"
)
if exist "%MSBUILD%" goto :build
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
echo %MSBUILD_VERSION_MAJOR% %MSBUILD_VERSION_MINOR%
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
popd
goto :EOF
:build
setlocal
"%MSBUILD%" -restore -maxcpucount %1 /p:Configuration=%2 /v:m %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
add a comment |
If you are adventurous you can also get the source code and latest release of MsBuild from GitHub now at https://github.com/Microsoft/msbuild/releases/
add a comment |
If You want to compile a Delphi project, look at "ERROR MSB4040 There is no target in the project" when using msbuild+Delphi2009
Correct answer there are said: "There is a batch file called rsvars.bat (search for it in the RAD Studio folder). Call that before calling MSBuild, and it will setup the necessary environment variables. Make sure the folders are correct in rsvars.bat if you have the compiler in a different location to the default."
This bat will not only update the PATH environment variable to proper .NET folder with proper MSBuild.exe version, but also registers other necessary variables.
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
1
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
add a comment |
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f328017%2fpath-to-msbuild%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
18 Answers
18
active
oldest
votes
18 Answers
18
active
oldest
votes
active
oldest
votes
active
oldest
votes
Poking around the registry, it looks like
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
may be what you're after; fire up regedit.exe and have a look.
Query via command line (per Nikolay Botev)
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
Query via PowerShell (per MovGP0)
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
4
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
6
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
2
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
6
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
2
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
|
show 3 more comments
Poking around the registry, it looks like
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
may be what you're after; fire up regedit.exe and have a look.
Query via command line (per Nikolay Botev)
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
Query via PowerShell (per MovGP0)
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
4
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
6
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
2
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
6
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
2
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
|
show 3 more comments
Poking around the registry, it looks like
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
may be what you're after; fire up regedit.exe and have a look.
Query via command line (per Nikolay Botev)
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
Query via PowerShell (per MovGP0)
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
Poking around the registry, it looks like
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
may be what you're after; fire up regedit.exe and have a look.
Query via command line (per Nikolay Botev)
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
Query via PowerShell (per MovGP0)
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
edited Nov 15 '18 at 16:04
jpaugh
3,95632569
3,95632569
answered Nov 29 '08 at 22:59
BrianBrian
107k15210282
107k15210282
4
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
6
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
2
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
6
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
2
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
|
show 3 more comments
4
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
6
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
2
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
6
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
2
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
4
4
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
I have installed Visual Studio 2017 RC and starting the Developer Command Prompt, the MSBuild version is 15.+, but this version doesn't show in the registry. How do I get access to the same MSBuild that the Dev Cmd Prompt is using?
– SuperJMN
Jan 7 '17 at 12:54
6
6
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
MSBuild 15 is located at `C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild15.0Binamd64`
– nZeus
Mar 3 '17 at 23:14
2
2
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
Only if you installed VS2017 there, I couldn't find a single entry point in the registry for MsBuildToolsPath for the 15.0 toolset
– Paciv
Mar 8 '17 at 11:15
6
6
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
docs.microsoft.com/en-us/visualstudio/msbuild/… "MSBuild is now installed in a folder under each version of Visual Studio. For example, C:Program Files (x86)Microsoft Visual Studio2017EnterpriseMSBuild" and "ToolsVersion values are no longer set in the registry"
– Hulvej
May 8 '17 at 13:47
2
2
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
@O.R.Mapper Microsoft offers a project on GitHub for determining paths of Visual Studio 2017/msbuild 15.x instances. It is a single executable which can be used by your build software/scripts.
– Roi Danton
Dec 22 '17 at 11:24
|
show 3 more comments
You can also print the path of MSBuild.exe to the command line:
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
1
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
2
@VictorIonescu: You can use/reg:32
or/reg:64
on both bitnessess ofcmd
(or whatever process you are running) to explicitly get that path.
– Simon Buchan
Apr 20 '16 at 1:53
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
add a comment |
You can also print the path of MSBuild.exe to the command line:
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
1
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
2
@VictorIonescu: You can use/reg:32
or/reg:64
on both bitnessess ofcmd
(or whatever process you are running) to explicitly get that path.
– Simon Buchan
Apr 20 '16 at 1:53
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
add a comment |
You can also print the path of MSBuild.exe to the command line:
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
You can also print the path of MSBuild.exe to the command line:
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions4.0" /v MSBuildToolsPath
edited Jun 19 '13 at 15:41
mathonnapkins
277
277
answered Mar 16 '13 at 7:13
Nikolay BotevNikolay Botev
1,490196
1,490196
1
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
2
@VictorIonescu: You can use/reg:32
or/reg:64
on both bitnessess ofcmd
(or whatever process you are running) to explicitly get that path.
– Simon Buchan
Apr 20 '16 at 1:53
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
add a comment |
1
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
2
@VictorIonescu: You can use/reg:32
or/reg:64
on both bitnessess ofcmd
(or whatever process you are running) to explicitly get that path.
– Simon Buchan
Apr 20 '16 at 1:53
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
1
1
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
Please note that if you want to build a windows phone app, that needs the 32 bits msbuild. Querying the registry gives only the 64 bit msbuild on a 64 bit machine.
– Victor Ionescu
Jul 3 '14 at 11:39
2
2
@VictorIonescu: You can use
/reg:32
or /reg:64
on both bitnessess of cmd
(or whatever process you are running) to explicitly get that path.– Simon Buchan
Apr 20 '16 at 1:53
@VictorIonescu: You can use
/reg:32
or /reg:64
on both bitnessess of cmd
(or whatever process you are running) to explicitly get that path.– Simon Buchan
Apr 20 '16 at 1:53
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
this will give you the path to an old (4.0) location - the one you probably want is actually elsewhere see stackoverflow.com/questions/32007871/…
– JonnyRaa
Apr 30 '18 at 10:29
add a comment |
If you want to use MSBuild for .Net 4 then you can use the following PowerShell command to get the executable's path. If you want version 2.0 or 3.5 then just change the $dotNetVersion variable.
To run the executable you'll need to prepend the $msbuild variable with &. That will execute the variable.
# valid versions are [2.0, 3.5, 4.0]
$dotNetVersion = "4.0"
$regKey = "HKLM:softwareMicrosoftMSBuildToolsVersions$dotNetVersion"
$regProperty = "MSBuildToolsPath"
$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"
&$msbuildExe
2
works also for$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)
– Julian
Nov 10 '16 at 11:12
3
Does not work for VS 2017, which does not add a value under theHKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir fromHKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then appendMSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.
– Ian Kemp
May 11 '17 at 10:59
add a comment |
If you want to use MSBuild for .Net 4 then you can use the following PowerShell command to get the executable's path. If you want version 2.0 or 3.5 then just change the $dotNetVersion variable.
To run the executable you'll need to prepend the $msbuild variable with &. That will execute the variable.
# valid versions are [2.0, 3.5, 4.0]
$dotNetVersion = "4.0"
$regKey = "HKLM:softwareMicrosoftMSBuildToolsVersions$dotNetVersion"
$regProperty = "MSBuildToolsPath"
$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"
&$msbuildExe
2
works also for$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)
– Julian
Nov 10 '16 at 11:12
3
Does not work for VS 2017, which does not add a value under theHKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir fromHKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then appendMSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.
– Ian Kemp
May 11 '17 at 10:59
add a comment |
If you want to use MSBuild for .Net 4 then you can use the following PowerShell command to get the executable's path. If you want version 2.0 or 3.5 then just change the $dotNetVersion variable.
To run the executable you'll need to prepend the $msbuild variable with &. That will execute the variable.
# valid versions are [2.0, 3.5, 4.0]
$dotNetVersion = "4.0"
$regKey = "HKLM:softwareMicrosoftMSBuildToolsVersions$dotNetVersion"
$regProperty = "MSBuildToolsPath"
$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"
&$msbuildExe
If you want to use MSBuild for .Net 4 then you can use the following PowerShell command to get the executable's path. If you want version 2.0 or 3.5 then just change the $dotNetVersion variable.
To run the executable you'll need to prepend the $msbuild variable with &. That will execute the variable.
# valid versions are [2.0, 3.5, 4.0]
$dotNetVersion = "4.0"
$regKey = "HKLM:softwareMicrosoftMSBuildToolsVersions$dotNetVersion"
$regProperty = "MSBuildToolsPath"
$msbuildExe = join-path -path (Get-ItemProperty $regKey).$regProperty -childpath "msbuild.exe"
&$msbuildExe
answered Nov 20 '12 at 17:32
AllenSanbornAllenSanborn
6601712
6601712
2
works also for$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)
– Julian
Nov 10 '16 at 11:12
3
Does not work for VS 2017, which does not add a value under theHKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir fromHKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then appendMSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.
– Ian Kemp
May 11 '17 at 10:59
add a comment |
2
works also for$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)
– Julian
Nov 10 '16 at 11:12
3
Does not work for VS 2017, which does not add a value under theHKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir fromHKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then appendMSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.
– Ian Kemp
May 11 '17 at 10:59
2
2
works also for
$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)– Julian
Nov 10 '16 at 11:12
works also for
$dotNetVersion
12.0 (vs 2013) and 14.0 (vs 2015) (if installed of course)– Julian
Nov 10 '16 at 11:12
3
3
Does not work for VS 2017, which does not add a value under the
HKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir from HKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then append MSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.– Ian Kemp
May 11 '17 at 10:59
Does not work for VS 2017, which does not add a value under the
HKLM:softwareMicrosoftMSBuildToolsVersions
key. Instead you need to get the VS2017 install dir from HKLM:SOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS715.0
, then append MSBuild15.0BinMSBuild.exe
to get the MSBuild EXE location.– Ian Kemp
May 11 '17 at 10:59
add a comment |
For cmd shell scripting in Windows 7, I use the following fragment in my batch file to find MSBuild.exe in the .NET Framework version 4. I assume version 4 is present, but don't assume the sub-version. This isn't totally general-purpose, but for quick scripts it may be helpful:
set msbuild.exe=
for /D %%D in (%SYSTEMROOT%Microsoft.NETFrameworkv4*) do set msbuild.exe=%%DMSBuild.exe
For my uses I'm exiting the batch file with an error if that didn't work:
if not defined msbuild.exe echo error: can't find MSBuild.exe & goto :eof
if not exist "%msbuild.exe%" echo error: %msbuild.exe%: not found & goto :eof
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
@yoyo What'sset bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?
– Elisée
May 17 '16 at 11:16
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
add a comment |
For cmd shell scripting in Windows 7, I use the following fragment in my batch file to find MSBuild.exe in the .NET Framework version 4. I assume version 4 is present, but don't assume the sub-version. This isn't totally general-purpose, but for quick scripts it may be helpful:
set msbuild.exe=
for /D %%D in (%SYSTEMROOT%Microsoft.NETFrameworkv4*) do set msbuild.exe=%%DMSBuild.exe
For my uses I'm exiting the batch file with an error if that didn't work:
if not defined msbuild.exe echo error: can't find MSBuild.exe & goto :eof
if not exist "%msbuild.exe%" echo error: %msbuild.exe%: not found & goto :eof
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
@yoyo What'sset bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?
– Elisée
May 17 '16 at 11:16
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
add a comment |
For cmd shell scripting in Windows 7, I use the following fragment in my batch file to find MSBuild.exe in the .NET Framework version 4. I assume version 4 is present, but don't assume the sub-version. This isn't totally general-purpose, but for quick scripts it may be helpful:
set msbuild.exe=
for /D %%D in (%SYSTEMROOT%Microsoft.NETFrameworkv4*) do set msbuild.exe=%%DMSBuild.exe
For my uses I'm exiting the batch file with an error if that didn't work:
if not defined msbuild.exe echo error: can't find MSBuild.exe & goto :eof
if not exist "%msbuild.exe%" echo error: %msbuild.exe%: not found & goto :eof
For cmd shell scripting in Windows 7, I use the following fragment in my batch file to find MSBuild.exe in the .NET Framework version 4. I assume version 4 is present, but don't assume the sub-version. This isn't totally general-purpose, but for quick scripts it may be helpful:
set msbuild.exe=
for /D %%D in (%SYSTEMROOT%Microsoft.NETFrameworkv4*) do set msbuild.exe=%%DMSBuild.exe
For my uses I'm exiting the batch file with an error if that didn't work:
if not defined msbuild.exe echo error: can't find MSBuild.exe & goto :eof
if not exist "%msbuild.exe%" echo error: %msbuild.exe%: not found & goto :eof
edited May 17 '16 at 16:55
answered Dec 6 '12 at 21:02
yoyoyoyo
5,33424242
5,33424242
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
@yoyo What'sset bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?
– Elisée
May 17 '16 at 11:16
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
add a comment |
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
@yoyo What'sset bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?
– Elisée
May 17 '16 at 11:16
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
Handy script - thankyou! :)
– xan
Jan 22 '13 at 10:18
@yoyo What's
set bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?– Elisée
May 17 '16 at 11:16
@yoyo What's
set bb.build.msbuild.exe=
for? Is it required or just an artifact of your setup?– Elisée
May 17 '16 at 11:16
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
@Elisée Oops, sorry, that's a copy/paste typo. In my environment I call the variable bb.build.msbuild.exe, I neglected to fix that instance when I pasted into the answer. Fixed now, thanks for pointing that out.
– yoyo
May 17 '16 at 16:56
add a comment |
You can use this very trial PowerShell Command to get the MSBuildToolsPath
from the registry.
PowerShell (from registry)
Resolve-Path HKLM:SOFTWAREMicrosoftMSBuildToolsVersions* |
Get-ItemProperty -Name MSBuildToolsPath
Output
MSBuildToolsPath : C:Program Files (x86)MSBuild12.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions12.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 12.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:Program Files (x86)MSBuild14.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions14.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 14.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v2.0.50727
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 2.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v3.5
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 3.5
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v4.0.30319
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 4.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
or from the filesystem
PowerShell (from file system)
Resolve-Path "C:Program Files (x86)MSBuild*Binamd64MSBuild.exe"
Resolve-Path "C:Program Files (x86)MSBuild*BinMSBuild.exe"
Output
Path
----
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild12.0BinMSBuild.exe
C:Program Files (x86)MSBuild14.0BinMSBuild.exe
1
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
add a comment |
You can use this very trial PowerShell Command to get the MSBuildToolsPath
from the registry.
PowerShell (from registry)
Resolve-Path HKLM:SOFTWAREMicrosoftMSBuildToolsVersions* |
Get-ItemProperty -Name MSBuildToolsPath
Output
MSBuildToolsPath : C:Program Files (x86)MSBuild12.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions12.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 12.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:Program Files (x86)MSBuild14.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions14.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 14.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v2.0.50727
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 2.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v3.5
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 3.5
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v4.0.30319
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 4.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
or from the filesystem
PowerShell (from file system)
Resolve-Path "C:Program Files (x86)MSBuild*Binamd64MSBuild.exe"
Resolve-Path "C:Program Files (x86)MSBuild*BinMSBuild.exe"
Output
Path
----
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild12.0BinMSBuild.exe
C:Program Files (x86)MSBuild14.0BinMSBuild.exe
1
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
add a comment |
You can use this very trial PowerShell Command to get the MSBuildToolsPath
from the registry.
PowerShell (from registry)
Resolve-Path HKLM:SOFTWAREMicrosoftMSBuildToolsVersions* |
Get-ItemProperty -Name MSBuildToolsPath
Output
MSBuildToolsPath : C:Program Files (x86)MSBuild12.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions12.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 12.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:Program Files (x86)MSBuild14.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions14.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 14.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v2.0.50727
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 2.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v3.5
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 3.5
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v4.0.30319
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 4.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
or from the filesystem
PowerShell (from file system)
Resolve-Path "C:Program Files (x86)MSBuild*Binamd64MSBuild.exe"
Resolve-Path "C:Program Files (x86)MSBuild*BinMSBuild.exe"
Output
Path
----
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild12.0BinMSBuild.exe
C:Program Files (x86)MSBuild14.0BinMSBuild.exe
You can use this very trial PowerShell Command to get the MSBuildToolsPath
from the registry.
PowerShell (from registry)
Resolve-Path HKLM:SOFTWAREMicrosoftMSBuildToolsVersions* |
Get-ItemProperty -Name MSBuildToolsPath
Output
MSBuildToolsPath : C:Program Files (x86)MSBuild12.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions12.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 12.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:Program Files (x86)MSBuild14.0binamd64
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions14.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 14.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v2.0.50727
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 2.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v3.5
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 3.5
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
MSBuildToolsPath : C:WindowsMicrosoft.NETFramework64v4.0.30319
PSPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions4.0
PSParentPath : Microsoft.PowerShell.CoreRegistry::HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions
PSChildName : 4.0
PSDrive : HKLM
PSProvider : Microsoft.PowerShell.CoreRegistry
or from the filesystem
PowerShell (from file system)
Resolve-Path "C:Program Files (x86)MSBuild*Binamd64MSBuild.exe"
Resolve-Path "C:Program Files (x86)MSBuild*BinMSBuild.exe"
Output
Path
----
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe
C:Program Files (x86)MSBuild12.0BinMSBuild.exe
C:Program Files (x86)MSBuild14.0BinMSBuild.exe
edited Jan 25 '18 at 9:50
answered Sep 3 '15 at 8:23
dhcgndhcgn
3,4192646
3,4192646
1
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
add a comment |
1
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
1
1
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
The best answer on this topic.
– Teoman shipahi
Feb 28 '17 at 19:58
add a comment |
@AllenSanborn has a great powershell version, but some folks have a requirement to use only batch scripts for builds.
This is an applied version of what @bono8106 answered.
msbuildpath.bat
@echo off
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath > nul 2>&1
if ERRORLEVEL 1 goto MissingMSBuildRegistry
for /f "skip=2 tokens=2,*" %%A in ('reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath') do SET "MSBUILDDIR=%%B"
IF NOT EXIST "%MSBUILDDIR%" goto MissingMSBuildToolsPath
IF NOT EXIST "%MSBUILDDIR%msbuild.exe" goto MissingMSBuildExe
exit /b 0
goto:eof
::ERRORS
::---------------------
:MissingMSBuildRegistry
echo Cannot obtain path to MSBuild tools from registry
goto:eof
:MissingMSBuildToolsPath
echo The MSBuild tools path from the registry '%MSBUILDDIR%' does not exist
goto:eof
:MissingMSBuildExe
echo The MSBuild executable could not be found at '%MSBUILDDIR%'
goto:eof
build.bat
@echo off
call msbuildpath.bat
"%MSBUILDDIR%msbuild.exe" foo.csproj /p:Configuration=Release
For Visual Studio 2017 / MSBuild 15, Aziz Atif (the guy who wrote Elmah) wrote a batch script
build.cmd Release Foo.csproj
https://github.com/linqpadless/LinqPadless/blob/master/build.cmd
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :restore
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
nuget restore ^
&& call :build Debug %* ^
&& call :build Release %*
popd
goto :EOF
:build
setlocal
"%MSBUILD%" /p:Configuration=%1 /v:m %2 %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
2
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
1
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
2
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
add a comment |
@AllenSanborn has a great powershell version, but some folks have a requirement to use only batch scripts for builds.
This is an applied version of what @bono8106 answered.
msbuildpath.bat
@echo off
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath > nul 2>&1
if ERRORLEVEL 1 goto MissingMSBuildRegistry
for /f "skip=2 tokens=2,*" %%A in ('reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath') do SET "MSBUILDDIR=%%B"
IF NOT EXIST "%MSBUILDDIR%" goto MissingMSBuildToolsPath
IF NOT EXIST "%MSBUILDDIR%msbuild.exe" goto MissingMSBuildExe
exit /b 0
goto:eof
::ERRORS
::---------------------
:MissingMSBuildRegistry
echo Cannot obtain path to MSBuild tools from registry
goto:eof
:MissingMSBuildToolsPath
echo The MSBuild tools path from the registry '%MSBUILDDIR%' does not exist
goto:eof
:MissingMSBuildExe
echo The MSBuild executable could not be found at '%MSBUILDDIR%'
goto:eof
build.bat
@echo off
call msbuildpath.bat
"%MSBUILDDIR%msbuild.exe" foo.csproj /p:Configuration=Release
For Visual Studio 2017 / MSBuild 15, Aziz Atif (the guy who wrote Elmah) wrote a batch script
build.cmd Release Foo.csproj
https://github.com/linqpadless/LinqPadless/blob/master/build.cmd
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :restore
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
nuget restore ^
&& call :build Debug %* ^
&& call :build Release %*
popd
goto :EOF
:build
setlocal
"%MSBUILD%" /p:Configuration=%1 /v:m %2 %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
2
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
1
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
2
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
add a comment |
@AllenSanborn has a great powershell version, but some folks have a requirement to use only batch scripts for builds.
This is an applied version of what @bono8106 answered.
msbuildpath.bat
@echo off
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath > nul 2>&1
if ERRORLEVEL 1 goto MissingMSBuildRegistry
for /f "skip=2 tokens=2,*" %%A in ('reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath') do SET "MSBUILDDIR=%%B"
IF NOT EXIST "%MSBUILDDIR%" goto MissingMSBuildToolsPath
IF NOT EXIST "%MSBUILDDIR%msbuild.exe" goto MissingMSBuildExe
exit /b 0
goto:eof
::ERRORS
::---------------------
:MissingMSBuildRegistry
echo Cannot obtain path to MSBuild tools from registry
goto:eof
:MissingMSBuildToolsPath
echo The MSBuild tools path from the registry '%MSBUILDDIR%' does not exist
goto:eof
:MissingMSBuildExe
echo The MSBuild executable could not be found at '%MSBUILDDIR%'
goto:eof
build.bat
@echo off
call msbuildpath.bat
"%MSBUILDDIR%msbuild.exe" foo.csproj /p:Configuration=Release
For Visual Studio 2017 / MSBuild 15, Aziz Atif (the guy who wrote Elmah) wrote a batch script
build.cmd Release Foo.csproj
https://github.com/linqpadless/LinqPadless/blob/master/build.cmd
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :restore
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
nuget restore ^
&& call :build Debug %* ^
&& call :build Release %*
popd
goto :EOF
:build
setlocal
"%MSBUILD%" /p:Configuration=%1 /v:m %2 %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
@AllenSanborn has a great powershell version, but some folks have a requirement to use only batch scripts for builds.
This is an applied version of what @bono8106 answered.
msbuildpath.bat
@echo off
reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath > nul 2>&1
if ERRORLEVEL 1 goto MissingMSBuildRegistry
for /f "skip=2 tokens=2,*" %%A in ('reg.exe query "HKLMSOFTWAREMicrosoftMSBuildToolsVersions14.0" /v MSBuildToolsPath') do SET "MSBUILDDIR=%%B"
IF NOT EXIST "%MSBUILDDIR%" goto MissingMSBuildToolsPath
IF NOT EXIST "%MSBUILDDIR%msbuild.exe" goto MissingMSBuildExe
exit /b 0
goto:eof
::ERRORS
::---------------------
:MissingMSBuildRegistry
echo Cannot obtain path to MSBuild tools from registry
goto:eof
:MissingMSBuildToolsPath
echo The MSBuild tools path from the registry '%MSBUILDDIR%' does not exist
goto:eof
:MissingMSBuildExe
echo The MSBuild executable could not be found at '%MSBUILDDIR%'
goto:eof
build.bat
@echo off
call msbuildpath.bat
"%MSBUILDDIR%msbuild.exe" foo.csproj /p:Configuration=Release
For Visual Studio 2017 / MSBuild 15, Aziz Atif (the guy who wrote Elmah) wrote a batch script
build.cmd Release Foo.csproj
https://github.com/linqpadless/LinqPadless/blob/master/build.cmd
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :restore
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
nuget restore ^
&& call :build Debug %* ^
&& call :build Release %*
popd
goto :EOF
:build
setlocal
"%MSBUILD%" /p:Configuration=%1 /v:m %2 %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
edited May 7 '18 at 17:59
answered Dec 6 '13 at 19:27
JJSJJS
4,1733658
4,1733658
2
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
1
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
2
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
add a comment |
2
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
1
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
2
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
2
2
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
Note: Since VS2017/msbuild 15.x doesn't use the registry for their paths, vswhere is an alternative to determine the msbuild path.
– Roi Danton
Dec 22 '17 at 11:27
1
1
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
Also, AzizAtif is the man. Take a gander at this for 15.1 builds - github.com/linqpadless/LinqPadless/blob/master/build.cmd
– JJS
Jan 31 '18 at 23:11
2
2
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
Also, vswhere can be installed via Chocolatey: chocolatey.org/packages/vswhere
– cowlinator
May 4 '18 at 21:34
add a comment |
The Registry locations
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
give the location for the executable.
But if you need the location where to save the Task extensions, it's on
%ProgramFiles%MSBuild
4
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
add a comment |
The Registry locations
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
give the location for the executable.
But if you need the location where to save the Task extensions, it's on
%ProgramFiles%MSBuild
4
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
add a comment |
The Registry locations
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
give the location for the executable.
But if you need the location where to save the Task extensions, it's on
%ProgramFiles%MSBuild
The Registry locations
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions2.0
HKEY_LOCAL_MACHINESOFTWAREMicrosoftMSBuildToolsVersions3.5
give the location for the executable.
But if you need the location where to save the Task extensions, it's on
%ProgramFiles%MSBuild
answered Dec 8 '08 at 19:08
Paulo SantosPaulo Santos
9,77533455
9,77533455
4
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
add a comment |
4
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
4
4
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
It's pretty old, I know - but anyway: on x64-Systems, the MSBuild-Folder is located in ProgramFiles(x86)
– Sascha
May 27 '11 at 23:21
add a comment |
This works for Visual Studio 2015 and 2017:
function Get-MSBuild-Path
$vs14key = "HKLM:SOFTWAREMicrosoftMSBuildToolsVersions14.0"
$vs15key = "HKLM:SOFTWAREwow6432nodeMicrosoftVisualStudioSxSVS7"
$msbuildPath = ""
if (Test-Path $vs14key)
$key = Get-ItemProperty $vs14key
$subkey = $key.MSBuildToolsPath
if ($subkey)
$msbuildPath = Join-Path $subkey "msbuild.exe"
if (Test-Path $vs15key)
$key = Get-ItemProperty $vs15key
$subkey = $key."15.0"
if ($subkey)
$msbuildPath = Join-Path $subkey "MSBuild15.0binamd64msbuild.exe"
return $msbuildPath
3
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
3
For Build Tools, usevswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.
– TN.
May 17 '17 at 15:53
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
add a comment |
This works for Visual Studio 2015 and 2017:
function Get-MSBuild-Path
$vs14key = "HKLM:SOFTWAREMicrosoftMSBuildToolsVersions14.0"
$vs15key = "HKLM:SOFTWAREwow6432nodeMicrosoftVisualStudioSxSVS7"
$msbuildPath = ""
if (Test-Path $vs14key)
$key = Get-ItemProperty $vs14key
$subkey = $key.MSBuildToolsPath
if ($subkey)
$msbuildPath = Join-Path $subkey "msbuild.exe"
if (Test-Path $vs15key)
$key = Get-ItemProperty $vs15key
$subkey = $key."15.0"
if ($subkey)
$msbuildPath = Join-Path $subkey "MSBuild15.0binamd64msbuild.exe"
return $msbuildPath
3
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
3
For Build Tools, usevswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.
– TN.
May 17 '17 at 15:53
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
add a comment |
This works for Visual Studio 2015 and 2017:
function Get-MSBuild-Path
$vs14key = "HKLM:SOFTWAREMicrosoftMSBuildToolsVersions14.0"
$vs15key = "HKLM:SOFTWAREwow6432nodeMicrosoftVisualStudioSxSVS7"
$msbuildPath = ""
if (Test-Path $vs14key)
$key = Get-ItemProperty $vs14key
$subkey = $key.MSBuildToolsPath
if ($subkey)
$msbuildPath = Join-Path $subkey "msbuild.exe"
if (Test-Path $vs15key)
$key = Get-ItemProperty $vs15key
$subkey = $key."15.0"
if ($subkey)
$msbuildPath = Join-Path $subkey "MSBuild15.0binamd64msbuild.exe"
return $msbuildPath
This works for Visual Studio 2015 and 2017:
function Get-MSBuild-Path
$vs14key = "HKLM:SOFTWAREMicrosoftMSBuildToolsVersions14.0"
$vs15key = "HKLM:SOFTWAREwow6432nodeMicrosoftVisualStudioSxSVS7"
$msbuildPath = ""
if (Test-Path $vs14key)
$key = Get-ItemProperty $vs14key
$subkey = $key.MSBuildToolsPath
if ($subkey)
$msbuildPath = Join-Path $subkey "msbuild.exe"
if (Test-Path $vs15key)
$key = Get-ItemProperty $vs15key
$subkey = $key."15.0"
if ($subkey)
$msbuildPath = Join-Path $subkey "MSBuild15.0binamd64msbuild.exe"
return $msbuildPath
answered Apr 26 '17 at 0:50
Raman ZhylichRaman Zhylich
2,6321919
2,6321919
3
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
3
For Build Tools, usevswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.
– TN.
May 17 '17 at 15:53
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
add a comment |
3
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
3
For Build Tools, usevswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.
– TN.
May 17 '17 at 15:53
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
3
3
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
For VS2017, see also: github.com/Microsoft/vswhere, github.com/Microsoft/vssetup.powershell, and github.com/deadlydog/Invoke-MsBuild
– Ian Kemp
May 17 '17 at 10:44
3
3
For Build Tools, use
vswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.– TN.
May 17 '17 at 15:53
For Build Tools, use
vswhere -products *
, as specified in github.com/Microsoft/vswhere/wiki/Find-MSBuild.– TN.
May 17 '17 at 15:53
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
For vswhere you should know the path where it is located. And of course you should have power-shell available for your build system. Just one question: why amd64? Does it have anything specific for building?
– Maxim
Aug 22 '17 at 18:41
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
Upvoted because this solution essentially just uses a registry key for MSBuild 15 too, not a third party library or script. Out of curiosity, what does "SxSVS7" refer to? Will that stay valid across VS versions?
– Lazlo
Dec 21 '18 at 20:51
add a comment |
easiest way might be to open PowerShell and enter
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
add a comment |
easiest way might be to open PowerShell and enter
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
add a comment |
easiest way might be to open PowerShell and enter
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
easiest way might be to open PowerShell and enter
dir HKLM:SOFTWAREMicrosoftMSBuildToolsVersions
answered Jul 14 '15 at 10:33
MovGP0MovGP0
3,13612626
3,13612626
add a comment |
add a comment |
On Windows 2003 and later, type this command in cmd:
cmd> where MSBuild
Sample result: C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
If nothing appears, it means that .NET framework is not included in the system PATH. The MSBuild should be in the .NET installation folder, along with .NET compilers (vbc.exe, csc.exe)
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
add a comment |
On Windows 2003 and later, type this command in cmd:
cmd> where MSBuild
Sample result: C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
If nothing appears, it means that .NET framework is not included in the system PATH. The MSBuild should be in the .NET installation folder, along with .NET compilers (vbc.exe, csc.exe)
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
add a comment |
On Windows 2003 and later, type this command in cmd:
cmd> where MSBuild
Sample result: C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
If nothing appears, it means that .NET framework is not included in the system PATH. The MSBuild should be in the .NET installation folder, along with .NET compilers (vbc.exe, csc.exe)
On Windows 2003 and later, type this command in cmd:
cmd> where MSBuild
Sample result: C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe
If nothing appears, it means that .NET framework is not included in the system PATH. The MSBuild should be in the .NET installation folder, along with .NET compilers (vbc.exe, csc.exe)
answered Sep 9 '15 at 13:20
draganicimwdraganicimw
5711
5711
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
add a comment |
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
This answer doesn't add much over other answers. It's less robust than this answer
– jpaugh
Nov 15 '18 at 15:49
add a comment |
Starting with MSBuild 2017 (v15), MSBuild is now installed in a folder under each version of Visual Studio
Here are some examples of where MSBuild.exe is found on my machine:
C:windowsMicrosoft.NETFrameworkv2.0.50727MSBuild.exe (v2.0.50727.8745 32-bit)
C:windowsMicrosoft.NETFramework64v2.0.50727MSBuild.exe (v2.0.50727.8745 64-bit)
C:WindowsMicrosoft.NETFrameworkv3.5MSBuild.exe (v3.5.30729.8763 32-bit)
C:WindowsMicrosoft.NETFramework64v3.5MSBuild.exe (v3.5.30729.8763 64-bit)
C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe (v4.7.2053.0 32-bit)
C:WindowsMicrosoft.NETFramework64v4.0.30319MSBuild.exe (v4.7.2053.0 64-bit)
C:Program Files (x86)MSBuild12.0BinMSBuild.exe (v12.0.21005.1 32-bit)
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe (v12.0.21005.1 64-bit)
C:Program Files (x86)MSBuild14.0BinMSBuild.exe (v14.0.25420.1 32-bit)
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe (v14.0.25420.1 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe (v15.1.1012+g251a9aec17 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binamd64MSBuild.exe (v15.1.1012+g251a9aec17 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinMSBuild.exe (v15.1.1012.6693 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinamd64MSBuild.exe (v15.1.1012.6693 64-bit)
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
add a comment |
Starting with MSBuild 2017 (v15), MSBuild is now installed in a folder under each version of Visual Studio
Here are some examples of where MSBuild.exe is found on my machine:
C:windowsMicrosoft.NETFrameworkv2.0.50727MSBuild.exe (v2.0.50727.8745 32-bit)
C:windowsMicrosoft.NETFramework64v2.0.50727MSBuild.exe (v2.0.50727.8745 64-bit)
C:WindowsMicrosoft.NETFrameworkv3.5MSBuild.exe (v3.5.30729.8763 32-bit)
C:WindowsMicrosoft.NETFramework64v3.5MSBuild.exe (v3.5.30729.8763 64-bit)
C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe (v4.7.2053.0 32-bit)
C:WindowsMicrosoft.NETFramework64v4.0.30319MSBuild.exe (v4.7.2053.0 64-bit)
C:Program Files (x86)MSBuild12.0BinMSBuild.exe (v12.0.21005.1 32-bit)
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe (v12.0.21005.1 64-bit)
C:Program Files (x86)MSBuild14.0BinMSBuild.exe (v14.0.25420.1 32-bit)
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe (v14.0.25420.1 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe (v15.1.1012+g251a9aec17 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binamd64MSBuild.exe (v15.1.1012+g251a9aec17 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinMSBuild.exe (v15.1.1012.6693 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinamd64MSBuild.exe (v15.1.1012.6693 64-bit)
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
add a comment |
Starting with MSBuild 2017 (v15), MSBuild is now installed in a folder under each version of Visual Studio
Here are some examples of where MSBuild.exe is found on my machine:
C:windowsMicrosoft.NETFrameworkv2.0.50727MSBuild.exe (v2.0.50727.8745 32-bit)
C:windowsMicrosoft.NETFramework64v2.0.50727MSBuild.exe (v2.0.50727.8745 64-bit)
C:WindowsMicrosoft.NETFrameworkv3.5MSBuild.exe (v3.5.30729.8763 32-bit)
C:WindowsMicrosoft.NETFramework64v3.5MSBuild.exe (v3.5.30729.8763 64-bit)
C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe (v4.7.2053.0 32-bit)
C:WindowsMicrosoft.NETFramework64v4.0.30319MSBuild.exe (v4.7.2053.0 64-bit)
C:Program Files (x86)MSBuild12.0BinMSBuild.exe (v12.0.21005.1 32-bit)
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe (v12.0.21005.1 64-bit)
C:Program Files (x86)MSBuild14.0BinMSBuild.exe (v14.0.25420.1 32-bit)
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe (v14.0.25420.1 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe (v15.1.1012+g251a9aec17 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binamd64MSBuild.exe (v15.1.1012+g251a9aec17 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinMSBuild.exe (v15.1.1012.6693 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinamd64MSBuild.exe (v15.1.1012.6693 64-bit)
Starting with MSBuild 2017 (v15), MSBuild is now installed in a folder under each version of Visual Studio
Here are some examples of where MSBuild.exe is found on my machine:
C:windowsMicrosoft.NETFrameworkv2.0.50727MSBuild.exe (v2.0.50727.8745 32-bit)
C:windowsMicrosoft.NETFramework64v2.0.50727MSBuild.exe (v2.0.50727.8745 64-bit)
C:WindowsMicrosoft.NETFrameworkv3.5MSBuild.exe (v3.5.30729.8763 32-bit)
C:WindowsMicrosoft.NETFramework64v3.5MSBuild.exe (v3.5.30729.8763 64-bit)
C:WindowsMicrosoft.NETFrameworkv4.0.30319MSBuild.exe (v4.7.2053.0 32-bit)
C:WindowsMicrosoft.NETFramework64v4.0.30319MSBuild.exe (v4.7.2053.0 64-bit)
C:Program Files (x86)MSBuild12.0BinMSBuild.exe (v12.0.21005.1 32-bit)
C:Program Files (x86)MSBuild12.0Binamd64MSBuild.exe (v12.0.21005.1 64-bit)
C:Program Files (x86)MSBuild14.0BinMSBuild.exe (v14.0.25420.1 32-bit)
C:Program Files (x86)MSBuild14.0Binamd64MSBuild.exe (v14.0.25420.1 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0BinMSBuild.exe (v15.1.1012+g251a9aec17 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017BuildToolsMSBuild15.0Binamd64MSBuild.exe (v15.1.1012+g251a9aec17 64-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinMSBuild.exe (v15.1.1012.6693 32-bit)
C:Program Files (x86)Microsoft Visual Studio2017LicenceNameMSBuildBinamd64MSBuild.exe (v15.1.1012.6693 64-bit)
edited Nov 16 '18 at 4:05
answered Aug 18 '17 at 20:01
cowlinatorcowlinator
1,43621322
1,43621322
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
add a comment |
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
According to a previous answer, 2017 does in fact store this information in the registry.
– jpaugh
Nov 15 '18 at 15:53
add a comment |
To retrieve path of msbuild 15 (Visual Studio 2017) with batch from registry w/o additional tools:
set regKey=HKLMSOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS7
set regValue=15.0
for /f "skip=2 tokens=3,*" %%A in ('reg.exe query %regKey% /v %regValue% 2^>nul') do (
set vs17path=%%A %%B
)
set msbuild15path = %vs17path%MSBuild15.0BinMSBuild.exe
Better available tools:
vswhere: Locate Visual Studio 2017 and newer installations, see get msbuild15 path with batch (uses hardcoded path as my snippet above).
Visual Studio Setup PowerShell Module by using Microsoft.VisualStudio.Workload.MSBuildTools
1
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
1
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
add a comment |
To retrieve path of msbuild 15 (Visual Studio 2017) with batch from registry w/o additional tools:
set regKey=HKLMSOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS7
set regValue=15.0
for /f "skip=2 tokens=3,*" %%A in ('reg.exe query %regKey% /v %regValue% 2^>nul') do (
set vs17path=%%A %%B
)
set msbuild15path = %vs17path%MSBuild15.0BinMSBuild.exe
Better available tools:
vswhere: Locate Visual Studio 2017 and newer installations, see get msbuild15 path with batch (uses hardcoded path as my snippet above).
Visual Studio Setup PowerShell Module by using Microsoft.VisualStudio.Workload.MSBuildTools
1
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
1
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
add a comment |
To retrieve path of msbuild 15 (Visual Studio 2017) with batch from registry w/o additional tools:
set regKey=HKLMSOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS7
set regValue=15.0
for /f "skip=2 tokens=3,*" %%A in ('reg.exe query %regKey% /v %regValue% 2^>nul') do (
set vs17path=%%A %%B
)
set msbuild15path = %vs17path%MSBuild15.0BinMSBuild.exe
Better available tools:
vswhere: Locate Visual Studio 2017 and newer installations, see get msbuild15 path with batch (uses hardcoded path as my snippet above).
Visual Studio Setup PowerShell Module by using Microsoft.VisualStudio.Workload.MSBuildTools
To retrieve path of msbuild 15 (Visual Studio 2017) with batch from registry w/o additional tools:
set regKey=HKLMSOFTWAREWOW6432NodeMicrosoftVisualStudioSxSVS7
set regValue=15.0
for /f "skip=2 tokens=3,*" %%A in ('reg.exe query %regKey% /v %regValue% 2^>nul') do (
set vs17path=%%A %%B
)
set msbuild15path = %vs17path%MSBuild15.0BinMSBuild.exe
Better available tools:
vswhere: Locate Visual Studio 2017 and newer installations, see get msbuild15 path with batch (uses hardcoded path as my snippet above).
Visual Studio Setup PowerShell Module by using Microsoft.VisualStudio.Workload.MSBuildTools
answered Dec 22 '17 at 14:10
Roi DantonRoi Danton
2,20322237
2,20322237
1
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
1
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
add a comment |
1
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
1
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
1
1
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
you saved my life
– Hakam Fostok
Jul 18 '18 at 10:25
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
There is already a PowerShell version of this. Circa 2017, is there any reason to avoid learning Powershell?
– jpaugh
Nov 15 '18 at 15:54
1
1
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
@jpaugh Not every build system has PowerShell available.
– Roi Danton
Nov 15 '18 at 21:52
add a comment |
As of Visual Studio 2017, the "correct" way to do this is by invoking %ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe
and appending the hardcoded path MSBuild15.0BinMSBuild.exe
to the output, as per Microsoft's official wiki article.
Yes, it's even worse than reading the Registry directly, which I didn't think was possible - but Microsoft finds a way.
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
add a comment |
As of Visual Studio 2017, the "correct" way to do this is by invoking %ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe
and appending the hardcoded path MSBuild15.0BinMSBuild.exe
to the output, as per Microsoft's official wiki article.
Yes, it's even worse than reading the Registry directly, which I didn't think was possible - but Microsoft finds a way.
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
add a comment |
As of Visual Studio 2017, the "correct" way to do this is by invoking %ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe
and appending the hardcoded path MSBuild15.0BinMSBuild.exe
to the output, as per Microsoft's official wiki article.
Yes, it's even worse than reading the Registry directly, which I didn't think was possible - but Microsoft finds a way.
As of Visual Studio 2017, the "correct" way to do this is by invoking %ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe
and appending the hardcoded path MSBuild15.0BinMSBuild.exe
to the output, as per Microsoft's official wiki article.
Yes, it's even worse than reading the Registry directly, which I didn't think was possible - but Microsoft finds a way.
answered Nov 15 '18 at 12:39
Ian KempIan Kemp
17.7k1272102
17.7k1272102
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
add a comment |
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
There are already 3 answers that mention vswhere, including your comment to that effect under one of them. Adding this answer just makes the answer soup worse.
– jpaugh
Nov 15 '18 at 15:59
add a comment |
An one-liner based on @dh_cgn's answer:
(Resolve-Path ([io.path]::combine($env:ProgramFiles(x86), 'Microsoft Visual Studio', '*', '*', 'MSBuild', '*' , 'bin' , 'msbuild.exe'))).Path
It selects all existing paths paths of eg. C:Program Files (x86)Microsoft Visual Studio**MSBuild*binmsbuild.exe
.
The wildcards stars are:
- the year (2017)
- the visual studio edition (community, professional, enterprise)
- the tools version (15.0)
Be aware that this command is selecting the first path that matches the expression ordered by alphabet. To narrow it down just replace the wildcards with specific elements eg. the year or tools version.
add a comment |
An one-liner based on @dh_cgn's answer:
(Resolve-Path ([io.path]::combine($env:ProgramFiles(x86), 'Microsoft Visual Studio', '*', '*', 'MSBuild', '*' , 'bin' , 'msbuild.exe'))).Path
It selects all existing paths paths of eg. C:Program Files (x86)Microsoft Visual Studio**MSBuild*binmsbuild.exe
.
The wildcards stars are:
- the year (2017)
- the visual studio edition (community, professional, enterprise)
- the tools version (15.0)
Be aware that this command is selecting the first path that matches the expression ordered by alphabet. To narrow it down just replace the wildcards with specific elements eg. the year or tools version.
add a comment |
An one-liner based on @dh_cgn's answer:
(Resolve-Path ([io.path]::combine($env:ProgramFiles(x86), 'Microsoft Visual Studio', '*', '*', 'MSBuild', '*' , 'bin' , 'msbuild.exe'))).Path
It selects all existing paths paths of eg. C:Program Files (x86)Microsoft Visual Studio**MSBuild*binmsbuild.exe
.
The wildcards stars are:
- the year (2017)
- the visual studio edition (community, professional, enterprise)
- the tools version (15.0)
Be aware that this command is selecting the first path that matches the expression ordered by alphabet. To narrow it down just replace the wildcards with specific elements eg. the year or tools version.
An one-liner based on @dh_cgn's answer:
(Resolve-Path ([io.path]::combine($env:ProgramFiles(x86), 'Microsoft Visual Studio', '*', '*', 'MSBuild', '*' , 'bin' , 'msbuild.exe'))).Path
It selects all existing paths paths of eg. C:Program Files (x86)Microsoft Visual Studio**MSBuild*binmsbuild.exe
.
The wildcards stars are:
- the year (2017)
- the visual studio edition (community, professional, enterprise)
- the tools version (15.0)
Be aware that this command is selecting the first path that matches the expression ordered by alphabet. To narrow it down just replace the wildcards with specific elements eg. the year or tools version.
edited Nov 15 '18 at 15:37
jpaugh
3,95632569
3,95632569
answered Nov 1 '18 at 1:21
SeriousMSeriousM
2,5351827
2,5351827
add a comment |
add a comment |
For Visual Studio 2017 without knowing the exact edition you could use this in a batch script:
FOR /F "tokens=* USEBACKQ" %%F IN (`where /r "%PROGRAMFILES(x86)%Microsoft Visual
Studio2017" msbuild.exe ^| findstr /v /i "amd64"`) DO (SET msbuildpath=%%F)
The findstr command is to ignore certain msbuild executables (in this example the amd64).
add a comment |
For Visual Studio 2017 without knowing the exact edition you could use this in a batch script:
FOR /F "tokens=* USEBACKQ" %%F IN (`where /r "%PROGRAMFILES(x86)%Microsoft Visual
Studio2017" msbuild.exe ^| findstr /v /i "amd64"`) DO (SET msbuildpath=%%F)
The findstr command is to ignore certain msbuild executables (in this example the amd64).
add a comment |
For Visual Studio 2017 without knowing the exact edition you could use this in a batch script:
FOR /F "tokens=* USEBACKQ" %%F IN (`where /r "%PROGRAMFILES(x86)%Microsoft Visual
Studio2017" msbuild.exe ^| findstr /v /i "amd64"`) DO (SET msbuildpath=%%F)
The findstr command is to ignore certain msbuild executables (in this example the amd64).
For Visual Studio 2017 without knowing the exact edition you could use this in a batch script:
FOR /F "tokens=* USEBACKQ" %%F IN (`where /r "%PROGRAMFILES(x86)%Microsoft Visual
Studio2017" msbuild.exe ^| findstr /v /i "amd64"`) DO (SET msbuildpath=%%F)
The findstr command is to ignore certain msbuild executables (in this example the amd64).
answered Nov 14 '18 at 8:54
Ernstjan FreriksErnstjan Freriks
1027
1027
add a comment |
add a comment |
add vswhere branch for https://github.com/linqpadless/LinqPadless/blob/master/build.cmd, works fine in my computer, and the vswhere branch works on my mate's computer.
May be, the vswhere branch should move forward as the first check.
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :build
for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe" -latest -requires Microsoft.Component.MSBuild`) do (
if /i "%%i"=="installationPath" set InstallDir=%%j
)
if exist "%InstallDir%MSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%InstallDir%MSBuild15.0BinMSBuild.exe"
)
if exist "%MSBUILD%" goto :build
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
echo %MSBUILD_VERSION_MAJOR% %MSBUILD_VERSION_MINOR%
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
popd
goto :EOF
:build
setlocal
"%MSBUILD%" -restore -maxcpucount %1 /p:Configuration=%2 /v:m %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
add a comment |
add vswhere branch for https://github.com/linqpadless/LinqPadless/blob/master/build.cmd, works fine in my computer, and the vswhere branch works on my mate's computer.
May be, the vswhere branch should move forward as the first check.
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :build
for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe" -latest -requires Microsoft.Component.MSBuild`) do (
if /i "%%i"=="installationPath" set InstallDir=%%j
)
if exist "%InstallDir%MSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%InstallDir%MSBuild15.0BinMSBuild.exe"
)
if exist "%MSBUILD%" goto :build
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
echo %MSBUILD_VERSION_MAJOR% %MSBUILD_VERSION_MINOR%
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
popd
goto :EOF
:build
setlocal
"%MSBUILD%" -restore -maxcpucount %1 /p:Configuration=%2 /v:m %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
add a comment |
add vswhere branch for https://github.com/linqpadless/LinqPadless/blob/master/build.cmd, works fine in my computer, and the vswhere branch works on my mate's computer.
May be, the vswhere branch should move forward as the first check.
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :build
for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe" -latest -requires Microsoft.Component.MSBuild`) do (
if /i "%%i"=="installationPath" set InstallDir=%%j
)
if exist "%InstallDir%MSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%InstallDir%MSBuild15.0BinMSBuild.exe"
)
if exist "%MSBUILD%" goto :build
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
echo %MSBUILD_VERSION_MAJOR% %MSBUILD_VERSION_MINOR%
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
popd
goto :EOF
:build
setlocal
"%MSBUILD%" -restore -maxcpucount %1 /p:Configuration=%2 /v:m %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
add vswhere branch for https://github.com/linqpadless/LinqPadless/blob/master/build.cmd, works fine in my computer, and the vswhere branch works on my mate's computer.
May be, the vswhere branch should move forward as the first check.
@echo off
setlocal
if "%PROCESSOR_ARCHITECTURE%"=="x86" set PROGRAMS=%ProgramFiles%
if defined ProgramFiles(x86) set PROGRAMS=%ProgramFiles(x86)%
for %%e in (Community Professional Enterprise) do (
if exist "%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%PROGRAMS%Microsoft Visual Studio2017%%eMSBuild15.0BinMSBuild.exe"
)
)
if exist "%MSBUILD%" goto :build
for /f "usebackq tokens=1* delims=: " %%i in (`"%ProgramFiles(x86)%Microsoft Visual StudioInstallervswhere.exe" -latest -requires Microsoft.Component.MSBuild`) do (
if /i "%%i"=="installationPath" set InstallDir=%%j
)
if exist "%InstallDir%MSBuild15.0BinMSBuild.exe" (
set "MSBUILD=%InstallDir%MSBuild15.0BinMSBuild.exe"
)
if exist "%MSBUILD%" goto :build
set MSBUILD=
for %%i in (MSBuild.exe) do set MSBUILD=%%~dpnx$PATH:i
if not defined MSBUILD goto :nomsbuild
set MSBUILD_VERSION_MAJOR=
set MSBUILD_VERSION_MINOR=
for /f "delims=. tokens=1,2,3,4" %%m in ('msbuild /version /nologo') do (
set MSBUILD_VERSION_MAJOR=%%m
set MSBUILD_VERSION_MINOR=%%n
)
echo %MSBUILD_VERSION_MAJOR% %MSBUILD_VERSION_MINOR%
if not defined MSBUILD_VERSION_MAJOR goto :nomsbuild
if not defined MSBUILD_VERSION_MINOR goto :nomsbuild
if %MSBUILD_VERSION_MAJOR% lss 15 goto :nomsbuild
if %MSBUILD_VERSION_MINOR% lss 1 goto :nomsbuild
:restore
for %%i in (NuGet.exe) do set nuget=%%~dpnx$PATH:i
if "%nuget%"=="" (
echo WARNING! NuGet executable not found in PATH so build may fail!
echo For more on NuGet, see https://github.com/nuget/home
)
pushd "%~dp0"
popd
goto :EOF
:build
setlocal
"%MSBUILD%" -restore -maxcpucount %1 /p:Configuration=%2 /v:m %3 %4 %5 %6 %7 %8 %9
goto :EOF
:nomsbuild
echo Microsoft Build version 15.1 (or later) does not appear to be
echo installed on this machine, which is required to build the solution.
exit /b 1
answered Jan 22 at 1:12
Shamork.FuShamork.Fu
14
14
add a comment |
add a comment |
If you are adventurous you can also get the source code and latest release of MsBuild from GitHub now at https://github.com/Microsoft/msbuild/releases/
add a comment |
If you are adventurous you can also get the source code and latest release of MsBuild from GitHub now at https://github.com/Microsoft/msbuild/releases/
add a comment |
If you are adventurous you can also get the source code and latest release of MsBuild from GitHub now at https://github.com/Microsoft/msbuild/releases/
If you are adventurous you can also get the source code and latest release of MsBuild from GitHub now at https://github.com/Microsoft/msbuild/releases/
answered yesterday
Dan DiploDan Diplo
22.4k45283
22.4k45283
add a comment |
add a comment |
If You want to compile a Delphi project, look at "ERROR MSB4040 There is no target in the project" when using msbuild+Delphi2009
Correct answer there are said: "There is a batch file called rsvars.bat (search for it in the RAD Studio folder). Call that before calling MSBuild, and it will setup the necessary environment variables. Make sure the folders are correct in rsvars.bat if you have the compiler in a different location to the default."
This bat will not only update the PATH environment variable to proper .NET folder with proper MSBuild.exe version, but also registers other necessary variables.
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
1
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
add a comment |
If You want to compile a Delphi project, look at "ERROR MSB4040 There is no target in the project" when using msbuild+Delphi2009
Correct answer there are said: "There is a batch file called rsvars.bat (search for it in the RAD Studio folder). Call that before calling MSBuild, and it will setup the necessary environment variables. Make sure the folders are correct in rsvars.bat if you have the compiler in a different location to the default."
This bat will not only update the PATH environment variable to proper .NET folder with proper MSBuild.exe version, but also registers other necessary variables.
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
1
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
add a comment |
If You want to compile a Delphi project, look at "ERROR MSB4040 There is no target in the project" when using msbuild+Delphi2009
Correct answer there are said: "There is a batch file called rsvars.bat (search for it in the RAD Studio folder). Call that before calling MSBuild, and it will setup the necessary environment variables. Make sure the folders are correct in rsvars.bat if you have the compiler in a different location to the default."
This bat will not only update the PATH environment variable to proper .NET folder with proper MSBuild.exe version, but also registers other necessary variables.
If You want to compile a Delphi project, look at "ERROR MSB4040 There is no target in the project" when using msbuild+Delphi2009
Correct answer there are said: "There is a batch file called rsvars.bat (search for it in the RAD Studio folder). Call that before calling MSBuild, and it will setup the necessary environment variables. Make sure the folders are correct in rsvars.bat if you have the compiler in a different location to the default."
This bat will not only update the PATH environment variable to proper .NET folder with proper MSBuild.exe version, but also registers other necessary variables.
answered Jun 15 '17 at 16:18
NashevNashev
1827
1827
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
1
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
add a comment |
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
1
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
There are already more robust answers here, circa 2008.
– jpaugh
Nov 15 '18 at 15:51
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
That answer is not Delphi-related and not more robust for Delphi users.
– Nashev
Nov 22 '18 at 11:14
1
1
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
Sorry for being terse. I meant more robust as in, works for more than just Delphi. There might be an easier way to do it in Delphi, but the OP didn't ask about Delphi, and this thread has some 18 answers that few will ever see. If it's important to you that others see this, I'd recommend that you create a new question specific to Delphi, and self-answer. If we got down to 6 or fewer answers that covered every version of MSBuild, I'd be very happy
– jpaugh
Nov 26 '18 at 15:46
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f328017%2fpath-to-msbuild%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown