How do I run MSBuild from the command line using Windows SDK
Option 1 (Best Option)
1 2 |
cd C:\ProjectFolder\ devenv Project.sln /rebuild |
Option 2
MSBuild is now part of Visual Studio.
in Command Prompt, you simply have to add the path to the .NET 4 Framework install on your machine to the
1 |
PATH |
environment variable.
You can access the environment variables by:
- Right-clicking on Computer
- Click Properties
- Then click Advanced system settings on the left navigation bar
- On the next dialog box click Environment variables
- Scroll down to
PATH
- Edit it to include your path to the framework (don’t forget a “;” after the last entry in here).
MSBuild is now located inside the Visual Studio folder.
For example:
1 2 3 |
c:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\ c:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\MSBuild\Current\Bin\ c:\Program Files (x86)\Microsoft Visual Studio\2019\Community\MSBuild\Current\Bin\ |
To dynamically find Visual Studio the following can be used:
1 |
"%ProgramFiles(x86)%\Microsoft Visual Studio\Installer\vswhere.exe" -latest -products * -requires Microsoft.Component.MSBuild -property installationPath |
1 |
D:\Program Files (x86)\Microsoft Visual Studio\2019\Professional |
For reference, my path was
1 |
C:\Windows\Microsoft.NET\Framework\v4.0.30319 |
Update:
As of MSBuild 12 (2013)/VS 2013/.NET 4.5.1+ and onward MSBuild is now installed as a part of Visual Studio.
For reference, with VS2015 installed my machine my path is
1 |
C:\Program Files (x86)\MSBuild\14.0\Bin |