|
@@ -13,10 +13,14 @@
|
|
|
Selects which channel of Visual Studio to install. Must be one of these values:
|
|
Selects which channel of Visual Studio to install. Must be one of these values:
|
|
|
Release (the default)
|
|
Release (the default)
|
|
|
Preview
|
|
Preview
|
|
|
|
|
+.PARAMETER Version
|
|
|
|
|
+ Selects which version of Visual Studio to install. Must be one of these values:
|
|
|
|
|
+ 2019 (the default)
|
|
|
|
|
+ 2022
|
|
|
.PARAMETER InstallPath
|
|
.PARAMETER InstallPath
|
|
|
The location on disk where Visual Studio should be installed or updated. Default path is location of latest
|
|
The location on disk where Visual Studio should be installed or updated. Default path is location of latest
|
|
|
existing installation of the specified edition, if any. If that VS edition is not currently installed, default
|
|
existing installation of the specified edition, if any. If that VS edition is not currently installed, default
|
|
|
- path is '${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\`$Edition".
|
|
|
|
|
|
|
+ path is '${env:ProgramFiles(x86)}\Microsoft Visual Studio\`$Version\`$Edition".
|
|
|
.PARAMETER Passive
|
|
.PARAMETER Passive
|
|
|
Run the installer without requiring interaction.
|
|
Run the installer without requiring interaction.
|
|
|
.PARAMETER Quiet
|
|
.PARAMETER Quiet
|
|
@@ -34,6 +38,8 @@ param(
|
|
|
[string]$Edition = 'Enterprise',
|
|
[string]$Edition = 'Enterprise',
|
|
|
[ValidateSet('Release', 'Preview')]
|
|
[ValidateSet('Release', 'Preview')]
|
|
|
[string]$Channel = 'Release',
|
|
[string]$Channel = 'Release',
|
|
|
|
|
+ [ValidateSet('2019', '2022')]
|
|
|
|
|
+ [string]$Version = '2019',
|
|
|
[string]$InstallPath,
|
|
[string]$InstallPath,
|
|
|
[switch]$Passive,
|
|
[switch]$Passive,
|
|
|
[switch]$Quiet
|
|
[switch]$Quiet
|
|
@@ -59,21 +65,28 @@ mkdir $intermedateDir -ErrorAction Ignore | Out-Null
|
|
|
$bootstrapper = "$intermedateDir\vsinstaller.exe"
|
|
$bootstrapper = "$intermedateDir\vsinstaller.exe"
|
|
|
$ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
|
|
$ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
|
|
|
|
|
|
|
|
-$channelUri = "https://aka.ms/vs/16/release"
|
|
|
|
|
-$responseFileName = "vs"
|
|
|
|
|
|
|
+if ("$Version" -eq "2019") {
|
|
|
|
|
+ $vsversion = 16;
|
|
|
|
|
+}
|
|
|
|
|
+if ("$Version" -eq "2022") {
|
|
|
|
|
+ $vsversion = 17;
|
|
|
|
|
+ $Channel = "Preview";
|
|
|
|
|
+}
|
|
|
|
|
+$channelUri = "https://aka.ms/vs/$vsversion/release"
|
|
|
|
|
+$responseFileName = "vs.$vsversion"
|
|
|
if ("$Edition" -eq "BuildTools") {
|
|
if ("$Edition" -eq "BuildTools") {
|
|
|
$responseFileName += ".buildtools"
|
|
$responseFileName += ".buildtools"
|
|
|
}
|
|
}
|
|
|
if ("$Channel" -eq "Preview") {
|
|
if ("$Channel" -eq "Preview") {
|
|
|
$responseFileName += ".preview"
|
|
$responseFileName += ".preview"
|
|
|
- $channelUri = "https://aka.ms/vs/16/pre"
|
|
|
|
|
|
|
+ $channelUri = "https://aka.ms/vs/$vsversion/pre"
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
$responseFile = "$PSScriptRoot\$responseFileName.json"
|
|
$responseFile = "$PSScriptRoot\$responseFileName.json"
|
|
|
$channelId = (Get-Content $responseFile | ConvertFrom-Json).channelId
|
|
$channelId = (Get-Content $responseFile | ConvertFrom-Json).channelId
|
|
|
|
|
|
|
|
$bootstrapperUri = "$channelUri/vs_$($Edition.ToLowerInvariant()).exe"
|
|
$bootstrapperUri = "$channelUri/vs_$($Edition.ToLowerInvariant()).exe"
|
|
|
-Write-Host "Downloading Visual Studio 2019 $Edition ($Channel) bootstrapper from $bootstrapperUri"
|
|
|
|
|
|
|
+Write-Host "Downloading Visual Studio $Version $Edition ($Channel) bootstrapper from $bootstrapperUri"
|
|
|
Invoke-WebRequest -Uri $bootstrapperUri -OutFile $bootstrapper
|
|
Invoke-WebRequest -Uri $bootstrapperUri -OutFile $bootstrapper
|
|
|
|
|
|
|
|
$productId = "Microsoft.VisualStudio.Product.$Edition"
|
|
$productId = "Microsoft.VisualStudio.Product.$Edition"
|
|
@@ -81,7 +94,7 @@ if (-not $InstallPath) {
|
|
|
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
|
$vsWhere = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe"
|
|
|
if (Test-Path $vsWhere)
|
|
if (Test-Path $vsWhere)
|
|
|
{
|
|
{
|
|
|
- $installations = & $vsWhere -version '[16,17)' -format json -prerelease -products $productId | ConvertFrom-Json |Sort-Object -Descending -Property installationVersion, installDate
|
|
|
|
|
|
|
+ $installations = & $vsWhere -version "[$vsversion,$($vsversion+1)))" -format json -prerelease -products $productId | ConvertFrom-Json |Sort-Object -Descending -Property installationVersion, installDate
|
|
|
foreach ($installation in $installations) {
|
|
foreach ($installation in $installations) {
|
|
|
Write-Host "Found '$($installation.installationName)' in '$($installation.installationPath)', channel = '$($installation.channelId)'"
|
|
Write-Host "Found '$($installation.installationName)' in '$($installation.installationPath)', channel = '$($installation.channelId)'"
|
|
|
if ($installation.channelId -eq $channelId) {
|
|
if ($installation.channelId -eq $channelId) {
|
|
@@ -93,10 +106,16 @@ if (-not $InstallPath) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
if (-not $InstallPath) {
|
|
if (-not $InstallPath) {
|
|
|
|
|
+ if ($vsversion -eq "16") {
|
|
|
|
|
+ $pathPrefix = "${env:ProgramFiles(x86)}";
|
|
|
|
|
+ }
|
|
|
|
|
+ if ($vsversion -eq "17") {
|
|
|
|
|
+ $pathPrefix = "${env:ProgramFiles}";
|
|
|
|
|
+ }
|
|
|
if ("$Channel" -eq "Preview") {
|
|
if ("$Channel" -eq "Preview") {
|
|
|
- $InstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\${Edition}_Pre"
|
|
|
|
|
|
|
+ $InstallPath = "$pathPrefix\Microsoft Visual Studio\$Version\${Edition}_Pre"
|
|
|
} else {
|
|
} else {
|
|
|
- $InstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\$Edition"
|
|
|
|
|
|
|
+ $InstallPath = "$pathPrefix\Microsoft Visual Studio\$Version\$Edition"
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
@@ -121,7 +140,7 @@ if ($Quiet) {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
Write-Host
|
|
Write-Host
|
|
|
-Write-Host "Installing Visual Studio 2019 $Edition ($Channel)" -f Magenta
|
|
|
|
|
|
|
+Write-Host "Installing Visual Studio $Version $Edition ($Channel)" -f Magenta
|
|
|
Write-Host
|
|
Write-Host
|
|
|
Write-Host "Running '$bootstrapper $arguments'"
|
|
Write-Host "Running '$bootstrapper $arguments'"
|
|
|
|
|
|