How to execute MSBuild command from a Windows batch (.bat) file?

Today I will share with you guys how to create the batch file and execute MSBuild command in Windows environment. In the batch file, you need to set the correct MSBuild.exe path depends on which Visual Studio version installed to your machine. Please check my previous article to set the correct location.

I am using the latest Visual Studio 2019 MSBuild location for below example. Open the new notepad file and copy the below commands.

@echo on
set MSBuildPath =" C:\Program Files (x86)\Microsoft Visual Studio\2019\BuildTools\MSBuild\Current\Bin\"

cd %MSBuildPath%
msbuild.exe "C:\<your-project-folder-path>\Build.csproj" /p:configuration=release

After that, please save the file with xxxx.bat extension. Now you are ready to execute the batch file.

That’s it. I hope this will help. 🙂
Photo: Internet

Leave a Reply

Your email address will not be published. Required fields are marked *