Skip to content

Update VS 2019 and add VS 2022 to Windows AMI #1175

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 9 additions & 8 deletions aws/ami/windows/scripts/Installers/Install-VS.ps1
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
# https://developercommunity.visualstudio.com/t/install-specific-version-of-vs-component/1142479
# Where to find the links: https://docs.microsoft.com/en-us/visualstudio/releases/2019/history#release-dates-and-build-numbers

# Where to find the links:
# - https://docs.microsoft.com/en-us/visualstudio/releases/2019/history#release-dates-and-build-numbers
# - https://learn.microsoft.com/en-us/visualstudio/releases/2022/release-history#fixed-version-bootstrappers
# BuildTools from S3
$VS_DOWNLOAD_LINK = "https://s3.amazonaws.com/ossci-windows/vs${env:VS_VERSION}_BuildTools.exe"
$VS_VERSION_major = [int] ${env:VS_VERSION}.split(".")[0]
$VS_DOWNLOAD_LINK = "https://aka.ms/vs/$VS_VERSION_major/release/vs_BuildTools.exe"
$COLLECT_DOWNLOAD_LINK = "https://aka.ms/vscollect.exe"
$VS_INSTALL_ARGS = @("--nocache","--quiet","--wait", "--add Microsoft.VisualStudio.Workload.VCTools",
"--add Microsoft.Component.MSBuild",
Expand All @@ -19,19 +21,18 @@ if (${env:INSTALL_WINDOWS_SDK} -eq "1") {
}

if (Test-Path "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe") {
$VS_VERSION_major = [int] ${env:VS_VERSION}.split(".")[0]
$existingPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products "Microsoft.VisualStudio.Product.BuildTools" -version "[${env:VS_VERSION}, ${env:VS_VERSION_major + 1})" -property installationPath
$existingPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products "Microsoft.VisualStudio.Product.BuildTools" -version "[${env:VS_VERSION}, ${VS_VERSION_major + 1})" -property installationPath
if (($existingPath -ne $null) -and (!${env:CIRCLECI})) {
echo "Found correctly versioned existing BuildTools installation in $existingPath"
exit 0
}
$pathToRemove = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -products "Microsoft.VisualStudio.Product.BuildTools" -property installationPath
}

echo "Downloading VS installer from S3."
echo "Downloading Visual Studio installer from $VS_DOWNLOAD_LINK."
curl.exe --retry 3 -kL $VS_DOWNLOAD_LINK --output vs_installer.exe
if ($LASTEXITCODE -ne 0) {
echo "Download of the VS 2019 Version ${env:VS_VERSION} installer failed"
echo "Download of the VS ${env:VS_YEAR} Version ${env:VS_VERSION} installer failed"
exit 1
}

Expand All @@ -52,7 +53,7 @@ $process = Start-Process "${PWD}\vs_installer.exe" -ArgumentList $VS_INSTALL_ARG
Remove-Item -Path vs_installer.exe -Force
$exitCode = $process.ExitCode
if (($exitCode -ne 0) -and ($exitCode -ne 3010)) {
echo "VS 2019 installer exited with code $exitCode, which should be one of [0, 3010]."
echo "VS ${env:VS_YEAR} installer exited with code $exitCode, which should be one of [0, 3010]."
curl.exe --retry 3 -kL $COLLECT_DOWNLOAD_LINK --output Collect.exe
if ($LASTEXITCODE -ne 0) {
echo "Download of the VS Collect tool failed."
Expand Down
20 changes: 18 additions & 2 deletions aws/ami/windows/windows.pkr.hcl
Original file line number Diff line number Diff line change
Expand Up @@ -55,15 +55,31 @@ build {
]
}

# Install the Visual Studio 2019
provisioner "powershell" {
environment_vars = ["INSTALL_WINDOWS_SDK=1", "VS_YEAR=2019", "VS_VERSION=16.11.21"]
execution_policy = "unrestricted"
scripts = [
"${path.root}/scripts/Installers/Install-VS.ps1",
]
}

# Install the Visual Studio 2022
provisioner "powershell" {
environment_vars = ["INSTALL_WINDOWS_SDK=1", "VS_YEAR=2022", "VS_VERSION=17.4.1"]
execution_policy = "unrestricted"
scripts = [
"${path.root}/scripts/Installers/Install-VS.ps1",
]
}

# Install the rest of the dependencies
provisioner "powershell" {
environment_vars = ["INSTALL_WINDOWS_SDK=1", "VS_VERSION=16.8.6"]
execution_policy = "unrestricted"
scripts = [
"${path.root}/scripts/Helpers/Reset-UserData.ps1",
"${path.root}/scripts/Installers/Install-Choco.ps1",
"${path.root}/scripts/Installers/Install-Tools.ps1",
"${path.root}/scripts/Installers/Install-VS.ps1",
]
}

Expand Down