Created
June 2, 2017 07:15
-
-
Save lennybacon/394d0f229d6de044407d9b24bd06530c to your computer and use it in GitHub Desktop.
Get latest MSBuild on x64 with Powershell
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
function Get-LatestMsBuild{ | |
$msbuild = Get-ChildItem -Path "C:\Program Files (x86)\Microsoft Visual Studio" | | |
? { !$PsIsContainer -and $_.Name.StartsWith("20") } | | |
% { @([System.IO.Path]::Combine($_.FullName, "Enterprise", "MsBuild"), [System.IO.Path]::Combine($_.FullName, "Professional", "MsBuild"), [System.IO.Path]::Combine($_.FullName, "Community", "MsBuild"))} | | |
? { (Test-Path -Path $_) } | | |
% { Get-ChildItem -Path $_ | ? { !$PsIsContainer -and $_.Name.StartsWith("1") } | Select-Object -Expand FullName } | | |
% { Get-ChildItem -Path $_ -Recurse | ? { !$PsIsContainer -and $_.FullName.EndsWith("amd64\msbuild.exe", "OrdinalIgnoreCase") } } | | |
Select-Object -First 1 | |
if($msbuild -ne $null){ | |
return $msbuild.FullName; | |
} | |
return ( ` | |
Get-ChildItem ` | |
-Path "C:\Program Files (x86)\MSBuild" ` | |
-Recurse ` | |
| Where-Object { ` | |
!$PsIsContainer -and ` | |
$_.FullName.EndsWith("amd64\msbuild.exe", "OrdinalIgnoreCase") ` | |
} ` | |
| sort FullName -Descending ` | |
| Select-Object -First 1` | |
).FullName | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment