Skip to content

Instantly share code, notes, and snippets.

@level120
Created September 6, 2022 01:52
Show Gist options
  • Select an option

  • Save level120/e6a4c2c72f3ca71254a4162264cab801 to your computer and use it in GitHub Desktop.

Select an option

Save level120/e6a4c2c72f3ca71254a4162264cab801 to your computer and use it in GitHub Desktop.
MSBuild auto found and building script
<#
.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