Skip to content

Commit 7475342

Browse files
authored
Add Vs install script (#4607)
1 parent 98f2973 commit 7475342

File tree

3 files changed

+98
-0
lines changed

3 files changed

+98
-0
lines changed

docs/BuildFromSource.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ Building ASP.NET Core on Windows requires:
1616
* Windows 7 or higher
1717
* At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
1818
* Visual Studio 2017. <https://visualstudio.com>
19+
* To install the exact required components, run scripts\install_vs.ps1. This will use VS2017.
1920
* Git. <https://git-scm.org>
2021
* (Optional) some optional components, like the SignalR Java client, may require
2122
* NodeJS <https://nodejs.org>

scripts/VsRequirements/vs.json

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
{
2+
"channelUri": "https://aka.ms/vs/15/release/channel",
3+
"channelId": "VisualStudio.15.Release",
4+
"productId": "Microsoft.VisualStudio.Product.Enterprise",
5+
"includeRecommended": false,
6+
"addProductLang": [
7+
"en-US"
8+
],
9+
"add": [
10+
"Microsoft.VisualStudio.Component.VC.Tools.x86.x64",
11+
"Microsoft.VisualStudio.Component.Windows81SDK",
12+
"Microsoft.Net.Component.4.7.2.TargetingPack",
13+
"Microsoft.Net.Component.4.7.2.SDK",
14+
"Microsoft.Net.Component.4.7.1.TargetingPack",
15+
"Microsoft.Net.Component.4.7.TargetingPack",
16+
"Microsoft.Net.Component.4.6.2.TargetingPack",
17+
"Microsoft.Net.Component.4.6.1.TargetingPack",
18+
"Microsoft.Net.Component.4.6.TargetingPack",
19+
"Microsoft.Net.Component.4.5.2.TargetingPack",
20+
"Microsoft.VisualStudio.ComponentGroup.NativeDesktop.Win81",
21+
"Microsoft.VisualStudio.Component.Azure.Storage.Emulator",
22+
"Microsoft.VisualStudio.Component.VC.ATL",
23+
"Microsoft.VisualStudio.Component.Windows10SDK.15063.Desktop",
24+
"Microsoft.VisualStudio.Component.Windows10SDK.17134",
25+
"Microsoft.VisualStudio.Workload.ManagedDesktop",
26+
"Microsoft.VisualStudio.Workload.NetWeb",
27+
"Microsoft.VisualStudio.Workload.NetCoreTools",
28+
"Microsoft.VisualStudio.Workload.NativeDesktop",
29+
"Microsoft.VisualStudio.Workload.VisualStudioExtension"
30+
]
31+
}

scripts/install_vs.ps1

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
<#
2+
.SYNOPSIS
3+
Installs or updates Visual Studio on a local developer machine
4+
.PARAMETER Update
5+
Update VS to latest version instead of modifying the installation to include new workloads.
6+
.PARAMETER Quiet
7+
Whether to run installer in the background
8+
#>
9+
[CmdletBinding(DefaultParameterSetName = 'Default')]
10+
param(
11+
[switch]$Update,
12+
[switch]$Quiet
13+
)
14+
15+
$ErrorActionPreference = 'Stop'
16+
Set-StrictMode -Version 1
17+
18+
$intermedateDir = "$PSScriptRoot\obj"
19+
mkdir $intermedateDir -ErrorAction Ignore | Out-Null
20+
21+
$bootstrapper = "$intermedateDir\vs_enterprise1.exe"
22+
Invoke-WebRequest -Uri 'https://aka.ms/vs/15/release/vs_enterprise.exe' -OutFile $bootstrapper
23+
24+
$vsJson = "$PSScriptRoot\VsRequirements\vs.json"
25+
# no backslashes - this breaks the installer
26+
$vsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise"
27+
$arguments = @(
28+
'--installPath', "`"$vsInstallPath`"",
29+
'--in', $vsJson,
30+
'--wait',
31+
'--norestart')
32+
33+
if ($Update) {
34+
$arguments = ,'update' + $arguments
35+
}
36+
else {
37+
$arguments = ,'modify' + $arguments
38+
}
39+
40+
if ($Quiet) {
41+
$arguments += '--quiet'
42+
}
43+
44+
Write-Host "Running '$bootstrapper $arguments' on $(hostname)"
45+
$process = Start-Process -FilePath $bootstrapper `
46+
-ArgumentList $arguments `
47+
-Verb runas `
48+
-PassThru `
49+
-ErrorAction Stop
50+
Write-Host "pid = $($process.Id)"
51+
Wait-Process -InputObject $process
52+
Write-Host "exit code = $($process.ExitCode)"
53+
54+
# https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio#error-codes
55+
if ($process.ExitCode -eq 3010) {
56+
Write-Warning "Agent $(hostname) requires restart to finish the VS update"
57+
}
58+
elseif ($process.ExitCode -eq 5007) {
59+
Write-Error "Operation was blocked - the computer does not meet the requirements"
60+
}
61+
elseif (($process.ExitCode -eq 5004) -or ($process.ExitCode -eq 1602)) {
62+
Write-Error "Operation was canceled"
63+
}
64+
elseif ($process.ExitCode -ne 0) {
65+
Write-Error "Installation failed on $(hostname) for unknown reason"
66+
}

0 commit comments

Comments
 (0)