Skip to content

Commit 9db0dc2

Browse files
AnnaOparevaAnna Opareva
andauthored
Add support for VS 2022 to the VSBuild, MSBuild, XamarinAndroid tasks (#15167)
* update MSBuildHelper, MsBuild, VSBuild * fix versions to 191.1 * fix versions to 191.0 Co-authored-by: Anna Opareva <[email protected]>
1 parent 26d8ca0 commit 9db0dc2

25 files changed

+81
-48
lines changed

Tasks/Common/MSBuildHelpers/PathFunctions.ps1

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,23 +12,27 @@ function Get-MSBuildPath {
1212
[string]$Version,
1313
[string]$Architecture)
1414

15+
$VersionNumber = [int]($Version.Remove(2))
16+
1517
Trace-VstsEnteringInvocation $MyInvocation
1618
try {
1719
# Only attempt to find Microsoft.Build.Utilities.Core.dll from a VS 15 Willow install
1820
# when "15.0" or latest is specified. In 15.0, the method GetPathToBuildToolsFile(...)
1921
# has regressed. When it is called for a version that is not found, the latest version
20-
# found is returned instead. Same for "16.0"
22+
# found is returned instead. Same for "16.0" and "17.0"
2123
[System.Reflection.Assembly]$msUtilities = $null
22-
if (($Version -eq "16.0" -or !$Version) -and # !$Version indicates "latest"
23-
($visualStudio16 = Get-VisualStudio 16) -and
24-
$visualStudio16.installationPath) {
2524

26-
$msbuildUtilitiesPath = [System.IO.Path]::Combine($visualStudio16.installationPath, "MSBuild\Current\Bin\Microsoft.Build.Utilities.Core.dll")
25+
if (($VersionNumber -ge 16 -or !$Version) -and # !$Version indicates "latest"
26+
($specifiedStudio = Get-VisualStudio $VersionNumber) -and
27+
$specifiedStudio.installationPath) {
28+
29+
$msbuildUtilitiesPath = [System.IO.Path]::Combine($specifiedStudio.installationPath, "MSBuild\Current\Bin\Microsoft.Build.Utilities.Core.dll")
2730
if (Test-Path -LiteralPath $msbuildUtilitiesPath -PathType Leaf) {
2831
Write-Verbose "Loading $msbuildUtilitiesPath"
2932
$msUtilities = [System.Reflection.Assembly]::LoadFrom($msbuildUtilitiesPath)
3033
}
3134
}
35+
3236
elseif (($Version -eq "15.0" -or !$Version) -and # !$Version indicates "latest"
3337
($visualStudio15 = Get-VisualStudio 15) -and
3438
$visualStudio15.installationPath) {
@@ -183,7 +187,7 @@ function Get-VisualStudio {
183187
[CmdletBinding()]
184188
param(
185189
[Parameter(Mandatory = $true)]
186-
[ValidateSet(15, 16)]
190+
[ValidateSet(15, 16, 17)]
187191
[int]$MajorVersion)
188192

189193
Trace-VstsEnteringInvocation $MyInvocation
@@ -273,7 +277,7 @@ function Select-MSBuildPath {
273277
}
274278

275279
$specificVersion = $PreferredVersion -and $PreferredVersion -ne 'latest'
276-
$versions = "16.0", '15.0', '14.0', '12.0', '4.0' | Where-Object { $_ -ne $PreferredVersion }
280+
$versions = '17.0', '16.0', '15.0', '14.0', '12.0', '4.0' | Where-Object { $_ -ne $PreferredVersion }
277281

278282
# Look for a specific version of MSBuild.
279283
if ($specificVersion) {

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.ErrorsIfVersionNotFound.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ Assert-WasCalled Get-MSBuildPath -- -Version '15.0' -Architecture 'Some architec
1313
Assert-WasCalled Get-MSBuildPath -- -Version '14.0' -Architecture 'Some architecture'
1414
Assert-WasCalled Get-MSBuildPath -- -Version '12.0' -Architecture 'Some architecture'
1515
Assert-WasCalled Get-MSBuildPath -- -Version '4.0' -Architecture 'Some architecture'
16-
Assert-WasCalled Get-MSBuildPath -Times 5
16+
Assert-WasCalled Get-MSBuildPath -Times 6

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.FallsBackFrom14.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ $actual = Select-MSBuildPath -Method 'Version' -Location '' -PreferredVersion '1
1212

1313
# Assert.
1414
Assert-WasCalled Write-Warning
15-
Assert-WasCalled Get-MSBuildPath -Times 4
15+
Assert-WasCalled Get-MSBuildPath -Times 5
1616
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.FallsBackFrom15.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ $actual = Select-MSBuildPath -Method 'Version' -Location '' -PreferredVersion '1
1212

1313
# Assert.
1414
Assert-WasCalled Write-Warning
15-
Assert-WasCalled Get-MSBuildPath -Times 3
15+
Assert-WasCalled Get-MSBuildPath -Times 4
1616
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.FallsBackFrom16.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ $actual = Select-MSBuildPath -Method 'Version' -Location '' -PreferredVersion '1
1212

1313
# Assert.
1414
Assert-WasCalled Write-Warning
15-
Assert-WasCalled Get-MSBuildPath -Times 2
15+
Assert-WasCalled Get-MSBuildPath -Times 3
1616
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.FallsForwardFrom12.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ $actual = Select-MSBuildPath -Method 'Version' -Location '' -PreferredVersion '1
1212

1313
# Assert.
1414
Assert-WasCalled Write-Warning
15-
Assert-WasCalled Get-MSBuildPath -Times 4
15+
Assert-WasCalled Get-MSBuildPath -Times 5
1616
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.FallsForwardFrom14.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ $actual = Select-MSBuildPath -Method 'Version' -Location '' -PreferredVersion '1
1212

1313
# Assert.
1414
Assert-WasCalled Write-Warning
15-
Assert-WasCalled Get-MSBuildPath -Times 3
15+
Assert-WasCalled Get-MSBuildPath -Times 4
1616
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.FallsForwardFrom15.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ $actual = Select-MSBuildPath -Method 'Version' -Location '' -PreferredVersion '1
1212

1313
# Assert.
1414
Assert-WasCalled Write-Warning
15-
Assert-WasCalled Get-MSBuildPath -Times 2
15+
Assert-WasCalled Get-MSBuildPath -Times 3
1616
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual

Tasks/Common/MSBuildHelpers/Tests/Select-MSBuildPath.ReturnsLatestVersion.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,5 +13,5 @@ foreach ($version in @('', 'latest')) {
1313

1414
# Assert.
1515
Assert-AreEqual -Expected 'Some resolved location' -Actual $actual
16-
Assert-WasCalled Get-MSBuildPath -Times 1
16+
Assert-WasCalled Get-MSBuildPath -Times 2
1717
}

Tasks/Common/MSBuildHelpers/package-lock.json

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)