From e9c0d8f353f7e8b177c1770285b4fa22eed56f7c Mon Sep 17 00:00:00 2001 From: Jared Parsons Date: Tue, 30 Jan 2018 13:58:50 -0800 Subject: [PATCH] Verify MSBuild version in Developer CMD prompt Roslyn is designed to have the simplest possible contribution story: clone then build. Every pre-req needed is either located on the machine or bootstrapped via NuGet. All the way down to using an xcopy MSBuild if needed. The one case which causes a problem is the VS command prompt. In this case MSBuild is pre-installed on the machine and may or may not be suitable for building Roslyn. Previously when building from a VS command prompt we just used whatever MSBuild was provided. The assumption being a developer command prompt was an explicit statement of whath MSBuild you wanted to use. Based on all of our customer reports though this does not seem to be the assumption that consumers of our repo have. The build gave them no explicit errors about the provided toolset and hence when the build failed they assigned flakiness to our repo. Going forward we are applying the same version validation to MSBuild when provided via a developer command prompt. If it doesn't match we will refuse to build asking the user to upgrade VS or build from a normal command prompt. --- build/scripts/build-utils.ps1 | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/build/scripts/build-utils.ps1 b/build/scripts/build-utils.ps1 index e059790f2a2..12136e7523b 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 -- GitLab