Skip to content

Commit 1529833

Browse files
authored
Use latest version of VS that is available (#2314)
* Use VS2017 or newer * Add missing pipeline
1 parent 064dcc1 commit 1529833

File tree

1 file changed

+33
-21
lines changed

1 file changed

+33
-21
lines changed

scripts/build.ps1

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ Param(
1616
# E.g. VS 2017 Update 1 Preview will have version 15.1.1
1717
[Parameter(Mandatory=$false)]
1818
[Alias("v")]
19-
[System.String] $Version = "", # Will set this later by reading TestPlatform.Settings.targets file.
19+
[System.String] $Version, # Will set this later by reading TestPlatform.Settings.targets file.
2020

2121
[Parameter(Mandatory=$false)]
2222
[Alias("vs")]
@@ -65,8 +65,12 @@ $env:TP_PACKAGE_PROJ_DIR = Join-Path $env:TP_ROOT_DIR "src\package"
6565
# Set Version from scripts/build/TestPlatform.Settings.targets
6666
if([string]::IsNullOrWhiteSpace($Version))
6767
{
68-
$Version = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Settings.targets)).Project.PropertyGroup.TPVersionPrefix
69-
$Version = ($Version).Trim()
68+
$Version = ([xml](Get-Content $env:TP_ROOT_DIR\scripts\build\TestPlatform.Settings.targets)).Project.PropertyGroup.TPVersionPrefix |
69+
Where-Object { $_ } |
70+
ForEach-Object { $_.Trim() } |
71+
Select-Object -First 1
72+
73+
Write-Verbose "Version was not provided using version '$Version' from TestPlatform.Settings.targets"
7074
}
7175

7276
#
@@ -564,12 +568,12 @@ function Create-VsixPackage
564568
Update-VsixVersion $vsixProjectDir
565569

566570
# Build vsix project to get TestPlatform.vsix
567-
Write-Verbose "$msbuildPath\msbuild.exe $vsixProjectDir\TestPlatform.csproj -p:Configuration=$Configuration"
568-
& $msbuildPath\msbuild.exe "$vsixProjectDir\TestPlatform.csproj" -p:Configuration=$Configuration
571+
Write-Verbose "$msbuildPath $vsixProjectDir\TestPlatform.csproj -p:Configuration=$Configuration"
572+
& $msbuildPath "$vsixProjectDir\TestPlatform.csproj" -p:Configuration=$Configuration
569573
}
570574
else
571-
{
572-
Write-Log ".. Create-VsixPackage: Cannot generate vsix as msbuild.exe not found at '$msbuildPath'."
575+
{
576+
throw ".. Create-VsixPackage: Cannot generate vsix as msbuild.exe not found at '$msbuildPath'."
573577
}
574578

575579
Write-Log "Create-VsixPackage: Complete. {$(Get-ElapsedTime($timer))}"
@@ -769,17 +773,16 @@ function PrintAndExit-OnError([System.String] $output)
769773
function Locate-MSBuildPath
770774
{
771775
$vsInstallPath = Locate-VsInstallPath
776+
$msbuildPath = Get-ChildItem (Join-Path -path $vsInstallPath -childPath "MSBuild\*\Bin\MSBuild.exe")
772777

773-
if([string]::IsNullOrEmpty($vsInstallPath))
774-
{
775-
return $null
778+
Write-Verbose "found msbuild : '$($msbuildPath -join "','")'"
779+
$msBuild = $msBuildPath | Select-Object -First 1
780+
Write-Verbose "msbuildPath is : '$($msbuildPath -join "','")'"
781+
if ($null -eq $msBuild -or 0 -eq $msBuild.Count) {
782+
throw "MSBuild not found."
776783
}
777784

778-
$vsInstallPath = Resolve-Path -path $vsInstallPath
779-
$msbuildPath = Join-Path -path $vsInstallPath -childPath "MSBuild\$env:MSBUILD_VERSION\Bin"
780-
781-
Write-Verbose "msbuildPath is : $msbuildPath"
782-
return $msbuildPath
785+
return $msBuild.FullName
783786
}
784787

785788
function Locate-VsInstallPath
@@ -796,22 +799,31 @@ function Locate-VsInstallPath
796799

797800
Try
798801
{
799-
Write-Verbose "VSWhere command line: $vswhere -version '(15.0,16.0]' -prerelease -products * -requires $requiredPackageIds -property installationPath"
800802
if ($TPB_CIBuild) {
801-
$vsInstallPath = & $vswhere -version '(15.0,16.0]' -products * -requires $requiredPackageIds -property installationPath
803+
Write-Verbose "VSWhere command line: $vswhere -version '(15.0' -products * -requires $requiredPackageIds -property installationPath"
804+
$vsInstallPath = & $vswhere -version '(15.0' -products * -requires $requiredPackageIds -property installationPath
802805
}
803806
else {
804807
# Allow using pre release versions of VS for dev builds
805-
$vsInstallPath = & $vswhere -version '(15.0,16.0]' -prerelease -products * -requires $requiredPackageIds -property installationPath
808+
Write-Verbose "VSWhere command line: $vswhere -version '(15.0' -prerelease -products * -requires $requiredPackageIds -property installationPath"
809+
$vsInstallPath = & $vswhere -version '(15.0' -prerelease -products * -requires $requiredPackageIds -property installationPath
806810
}
807811
}
808812
Catch [System.Management.Automation.MethodInvocationException]
809813
{
810-
Write-Verbose "Failed to find VS installation with requirements : $requiredPackageIds"
814+
throw "Failed to find VS installation with requirements: $requiredPackageIds"
815+
}
816+
817+
if ($null -eq $vsInstallPath -or 0 -eq @($vsInstallPath).Count) {
818+
throw "Failed to find VS installation with requirements: $requiredPackageIds"
819+
}
820+
else {
821+
Write-Verbose "Found VS installation with requirements '$($requiredPackageIds -join "','")' : '$($vsInstallPath -join "','")'."
811822
}
812823

813-
Write-Verbose "VSInstallPath is : $vsInstallPath"
814-
return $vsInstallPath
824+
$vsPath = $vsInstallPath | Select-Object -First 1
825+
Write-Verbose "VSInstallPath is : $vsPath"
826+
return $vsPath
815827
}
816828

817829
function Update-VsixVersion($vsixProjectDir)

0 commit comments

Comments
 (0)