Created
February 16, 2011 10:39
-
-
Save jstangroome/829169 to your computer and use it in GitHub Desktop.
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
# effectively this is VB's Option Strict On but for PowerShell | |
$ErrorActionPreference = 'Stop' | |
Set-StrictMode -Version Latest | |
$buildFile = "build\Build.proj" | |
# simulate the variable representing the folder this script is in (a PS Module would get this by default) | |
$PSScriptRoot = ($MyInvocation.MyCommand.Path | Split-Path | Resolve-Path).ProviderPath | |
# never pass relative paths outside your script | |
$absoluteBuildFile = $PSScriptRoot | Join-Path -ChildPath $buildFile | |
# ask the registry for the path to the .NET 4.0 framework. | |
# there is a better API but to ask for the .NET 4 path you need to be running CLR 4 and PowerShell is only CLR 2 | |
$fxPath = (Get-ItemProperty "HKLM:\SOFTWARE\Microsoft\NET Framework Setup\NDP\v4\Full").InstallPath | |
# build as per normal but passing the full project path | |
$msbuildPath = Join-Path -Path $fxPath -ChildPath "MSBuild.exe" | |
& $msbuildpath $absoluteBuildfile /t:Build /v:m | |
# PowerShell often ignores the exit code of external commands, let's check explicitly | |
# (the ISE and PS Remoting sessions however will detect STDERR output and convert that to PS errors) | |
if (-not $?) { throw "MSBuild failed with exit code $LastExitCode" } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment