Skip to content

Commit

Permalink
Updated validating VS toolset generic for different VS versions (#2551)
Browse files Browse the repository at this point in the history
  • Loading branch information
jainaashish authored Dec 6, 2018
1 parent 627d091 commit 86752f1
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 9 deletions.
28 changes: 24 additions & 4 deletions build/common.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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'
Expand Down Expand Up @@ -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)) {
Expand All @@ -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
Expand Down
13 changes: 8 additions & 5 deletions configure.ps1
Original file line number Diff line number Diff line change
Expand Up @@ -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 })
}
}
Expand Down

0 comments on commit 86752f1

Please sign in to comment.