Created
September 6, 2022 01:52
-
-
Save level120/e6a4c2c72f3ca71254a4162264cab801 to your computer and use it in GitHub Desktop.
MSBuild auto found and building script
This file contains hidden or 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
| <# | |
| .SYNOPSIS | |
| msbuild build script. | |
| .PARAMETER path | |
| Build target path. | |
| #> | |
| param( | |
| [Parameter(mandatory)] | |
| [string] $path, | |
| [string] $buildConfiguration = "Release", | |
| [string] $buildPlatform = "" | |
| ) | |
| $vsWherePath = "$(${env:ProgramFiles(x86)})\Microsoft Visual Studio\Installer\vswhere.exe" | |
| $vsWhereArgs = @( | |
| "-latest", | |
| "-requires", | |
| "Microsoft.Component.MSBuild", | |
| "-find", | |
| "MSBuild\**\Bin\MSBuild.exe" | |
| ) | |
| $msbuildPath = & $vsWherePath $vsWhereArgs | |
| $msbuildArgs = @( | |
| "-restore", | |
| "-target:Clean;Restore;Rebuild", | |
| "-property:Configuration=$buildConfiguration", | |
| "-property:WarningLevel=0", | |
| "-verbosity:minimal", | |
| "-consoleloggerparameters:ErrorsOnly", | |
| "$path" | |
| ) | |
| if ($buildPlatform -ne "") | |
| { | |
| $msbuildArgs += "-property:Platform=$buildPlatform" | |
| } | |
| if (Test-Path -Path $msbuildPath) | |
| { | |
| Write-Host "Found msbuild: `"$msbuildPath`"" -ForegroundColor Green | |
| } | |
| else | |
| { | |
| Write-Host "MSBuild not found." -ForegroundColor Red | |
| Exit | |
| } | |
| Write-Host "Start build..." -ForegroundColor Magenta | |
| & $msbuildPath $msbuildArgs | |
| Write-Host "Done." -ForegroundColor Magenta |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment