diff --git a/build/common.ps1 b/build/common.ps1 index fe940e1d4b5..c8fb09302da 100644 --- a/build/common.ps1 +++ b/build/common.ps1 @@ -2,6 +2,7 @@ $DefaultConfiguration = 'debug' $DefaultReleaseLabel = 'zlocal' $DefaultMSBuildVersion = 15 +$DefaultVSVersion = "15.0" # The pack version can be inferred from the .nuspec files on disk. This is only necessary as long # as the following issue is open: https://github.com/NuGet/Home/issues/3530 @@ -15,6 +16,7 @@ $Nupkgs = Join-Path $Artifacts nupkgs $ReleaseNupkgs = Join-Path $Artifacts ReleaseNupkgs $ConfigureJson = Join-Path $Artifacts configure.json $VsWhereExe = "${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" +$VSVersion = $env:VisualStudioVersion $DotNetExe = Join-Path $CLIRoot 'dotnet.exe' $NuGetExe = Join-Path $NuGetClientRoot '.nuget\nuget.exe' @@ -315,16 +317,35 @@ Function Get-LatestVisualStudioRoot() { Error-Log 'Cannot find an instance of Visual Studio 2017 or newer' -Fatal } +Function Get-VSVersion() { + if (-not $VSVersion) { + $VSVersion = $DefaultVSVersion + } + return $VSVersion +} + +Function Get-VSMajorVersion() { + $vsVersion = Get-VSVersion + $vsMajorVersion = "${vsVersion}".Split('.')[0] + return $vsMajorVersion +} + Function Get-MSBuildRoot { param( [switch]$Default ) + + $vsMajorVersion = Get-VSMajorVersion + # Willow install workaround if (-not $Default) { + # Find version 15.0 or newer - if (Test-Path Env:\VS150COMNTOOLS) { + $CommonToolsVar = "Env:VS${vsMajorVersion}0COMNTOOLS" + if (Test-Path $CommonToolsVar) { # If VS "15" is installed get msbuild from VS install path - $MSBuildRoot = Join-Path $env:VS150COMNTOOLS '..\..\MSBuild' + $CommonToolsValue = gci $CommonToolsVar | select -expand value -ea Ignore + $MSBuildRoot = Join-Path $CommonToolsValue '..\..\MSBuild' -Resolve } else { $VisualStudioRoot = Get-LatestVisualStudioRoot if ($VisualStudioRoot -and (Test-Path $VisualStudioRoot)) { @@ -344,12 +365,11 @@ Function Get-MSBuildRoot { Function Get-MSBuildExe { param( - [ValidateSet(15)] [int]$MSBuildVersion ) # Get the highest msbuild version if version was not specified if (-not $MSBuildVersion) { - return Get-MSBuildExe 15 + return Get-MSBuildExe $DefaultMSBuildVersion } $MSBuildRoot = Get-MSBuildRoot diff --git a/configure.ps1 b/configure.ps1 index 1640d3e9385..f1f9d0cbc11 100644 --- a/configure.ps1 +++ b/configure.ps1 @@ -129,20 +129,23 @@ if (-not $ProgramFiles -or -not (Test-Path $ProgramFiles)) { $MSBuildDefaultRoot = Get-MSBuildRoot $MSBuildRelativePath = 'bin\msbuild.exe' -Invoke-BuildStep 'Validating VS15 toolset installation' { - $vs15 = New-BuildToolset 15 +Invoke-BuildStep 'Validating VS toolset installation' { + + $vsMajorVersion = Get-VSMajorVersion + $vs15 = New-BuildToolset $vsMajorVersion if ($vs15) { $ConfigureObject.Toolsets.Add('vs15', $vs15) - $script:MSBuildExe = Get-MSBuildExe 15 + $script:MSBuildExe = Get-MSBuildExe $vsMajorVersion + $vsVersion = Get-VSVersion # Hack VSSDK path - $VSToolsPath = Join-Path $MSBuildDefaultRoot 'Microsoft\VisualStudio\v15.0' + $VSToolsPath = Join-Path $MSBuildDefaultRoot "Microsoft\VisualStudio\v${vsVersion}" $Targets = Join-Path $VSToolsPath 'VSSDK\Microsoft.VsSDK.targets' if (-not (Test-Path $Targets)) { Warning-Log "VSSDK is not found at default location '$VSToolsPath'. Attempting to override." # Attempting to fix VS SDK path for VS15 willow install builds # as MSBUILD failes to resolve it correctly - $VSToolsPath = Join-Path $vs15.VisualStudioInstallDir '..\..\MSBuild\Microsoft\VisualStudio\v15.0' -Resolve + $VSToolsPath = Join-Path $vs15.VisualStudioInstallDir "..\..\MSBuild\Microsoft\VisualStudio\v${vsVersion}" -Resolve $ConfigureObject.Add('EnvVars', @{ VSToolsPath = $VSToolsPath }) } }