Last active
August 2, 2021 09:31
-
-
Save mattou07/d0eabdb4bef6a45d263983ec64d42d72 to your computer and use it in GitHub Desktop.
Build your Visual Studio Solution without "Opening" Visual Studio (You still need it installed)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Place me in the same folder as the sln file | |
#Get the path of the sln file | |
Get-ChildItem -Path .\ -Filter *.sln -Recurse -File | ForEach-Object { | |
$solution = $_.FullName | |
} | |
#If you don't have Visual Studio Professional update the path to use a different edition i.e Community or Enterprise. Make sure MsBuild.exe is located there | |
cmd /c "`"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MsBuild.exe`" `"$solution`" /t:Restore" | |
cmd /c "`"C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\MSBuild\15.0\Bin\MsBuild.exe`" `"$solution`" /t:Rebuild" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Noticed the paths for the MsBuild.exe are looking at 2017 installs of VS. I would suggest a possible improvement would be to use the new mswhere.exe to find the latest version of MsBuild on a machine:
https://github.com/Microsoft/vswhere/wiki/Find-MSBuild
This powershell will return the path of the msbuild which could be used as a variable in your script:
&"${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -prerelease -products * -requires Microsoft.Component.MSBuild -find MSBuild**\Bin\MSBuild.exe
For systems without VS installed, vswhere is a standalone exe that can be downloaded onto systems and run to find the latest MSBuild.exe if one exists.