Skip to content

Commit

Permalink
Build script finds the latest version of msbuild, instead of relying …
Browse files Browse the repository at this point in the history
…on similar logic in psake, as a step towards phasing out psake. Lookup logic adapted from https://github.com/ligershark/psbuild/blob/master/src/psbuild.psm1.
  • Loading branch information
plioi committed Jun 8, 2016
1 parent c7666af commit 88d6422
Showing 1 changed file with 32 additions and 2 deletions.
34 changes: 32 additions & 2 deletions build.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,9 @@ task Test {
}

function compile-solution {
exec { msbuild /t:clean /v:q /nologo /p:Configuration=$configuration src\Parsley.sln }
exec { msbuild /t:build /v:q /nologo /p:Configuration=$configuration src\Parsley.sln }
Set-Alias msbuild (get-msbuild-path)
exec { msbuild /t:clean /v:q /nologo /p:Configuration=$configuration src\Parsley.sln }
exec { msbuild /t:build /v:q /nologo /p:Configuration=$configuration src\Parsley.sln }
}

function generate-assembly-info {
Expand Down Expand Up @@ -115,3 +116,32 @@ function regenerate-file($path, $newContent) {
[System.IO.File]::WriteAllText($path, $newContent, [System.Text.Encoding]::UTF8)
}
}

function get-msbuild-path {
[cmdletbinding()]
param(
[Parameter(Position=0)]
[ValidateSet('32bit','64bit')]
[string]$bitness = '32bit'
)
process{

# Find the highest installed version of msbuild.exe.

$regLocalKey = $null

if($bitness -eq '32bit'){
$regLocalKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,[Microsoft.Win32.RegistryView]::Registry32)
} else {
$regLocalKey = [Microsoft.Win32.RegistryKey]::OpenBaseKey([Microsoft.Win32.RegistryHive]::LocalMachine,[Microsoft.Win32.RegistryView]::Registry64)
}

$versionKeyName = $regLocalKey.OpenSubKey('SOFTWARE\Microsoft\MSBuild\ToolsVersions\').GetSubKeyNames() | Sort-Object {[double]$_} -Descending

$keyToReturn = ('SOFTWARE\Microsoft\MSBuild\ToolsVersions\{0}' -f $versionKeyName)

$path = ( '{0}msbuild.exe' -f $regLocalKey.OpenSubKey($keyToReturn).GetValue('MSBuildToolsPath'))

return $path
}
}

0 comments on commit 88d6422

Please sign in to comment.