diff --git a/build/scripts/build-utils.ps1 b/build/scripts/build-utils.ps1 index e059790f2a2ee91040eefd9765cd7d9ceaae35a3..12136e7523b0dfd463cbb1c6d2517db1cd17ad67 100644 --- a/build/scripts/build-utils.ps1 +++ b/build/scripts/build-utils.ps1 @@ -312,15 +312,21 @@ function Get-MSBuildKindAndDir([switch]$xcopy = $false) { return } - # MSBuild from an active VS command prompt. + # MSBuild from an active VS command prompt. Use the MSBuild here so long as it's from a + # compatible Visual Studio. If not though throw and error out. Given the number of + # environment variable changes in a developer command prompt it's hard to make guarantees + # about subbing in a new MSBuild instance if (${env:VSINSTALLDIR} -ne $null) { $command = (Get-Command msbuild -ErrorAction SilentlyContinue) - if ($command -ne $null) { + if ((Test-SupportedVisualStudioVersion ${env:VSCMD_VER}) -and ($command -ne $null) ) { $p = Split-Path -parent $command.Path Write-Output "vscmd" Write-Output $p return } + else { + throw "Developer Command Prompt for VS $(${env:VSCMD_VER}) is not recent enough. Please upgrade or build from a normal CMD window" + } } # Look for a valid VS installation @@ -353,6 +359,19 @@ function Get-MSBuildDir([switch]$xcopy = $false) { return $both[1] } + +# Dose this version of Visual Studio meet our minimum requirements for building. +function Test-SupportedVisualStudioVersion([string]$version) { + if (-not ($version -match "^([\d.]+)(\+|-)?.*$")) { + Write-Host "here" + return $false + } + + $V = New-Object System.Version $matches[1] + $min = New-Object System.Version "15.3" + return $v -ge $min; +} + # Get the directory and instance ID of the first Visual Studio version which # meets our minimal requirements for the Roslyn repo. function Get-VisualStudioDirAndId() { @@ -365,10 +384,8 @@ function Get-VisualStudioDirAndId() { # set of SDK fixes. Parsing the installationName is the only place where this is # recorded in that form. $name = $obj.installationName - if ($name -match "VisualStudio(Preview)?/([\d.]+)(\+|-).*") { - $minVersion = New-Object System.Version "15.3.0" - $version = New-Object System.Version $matches[2] - if ($version -ge $minVersion) { + if ($name -match "VisualStudio(Preview)?/(.*)") { + if (Test-SupportedVisualStudioVersion $matches[2]) { Write-Output $obj.installationPath Write-Output $obj.instanceId return