Improve InstallVisualStudio.ps1 (#6089)

* Support installing Community, Professional, or Enterprise versions of VS.
* Remove messages about build agents.
* Add examples to docs and the help output.
This commit is contained in:
Nate McMaster 2018-12-21 14:55:31 -08:00 committed by GitHub
parent f111a2d73a
commit 4eb495c74f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 65 additions and 48 deletions

View File

@ -231,9 +231,9 @@ elseif ($Projects) {
$MSBuildArguments += "/p:Projects=$Projects" $MSBuildArguments += "/p:Projects=$Projects"
} }
else { else {
# When adding new sub-group build flags, add them to this check # When adding new sub-group build flags, add them to this check.
if((-not $Native) -and (-not $Managed) -and (-not $NodeJS)) { if((-not $Native) -and (-not $Managed) -and (-not $NodeJS)) {
Write-Warning "No default group of projects was specified, so building the 'managed' and 'native' subset of projects. Run ``build.cmd -help`` for more details." Write-Warning "No default group of projects was specified, so building the 'managed' subset of projects. Run ``build.cmd -help`` for more details."
# This goal of this is to pick a sensible default for `build.cmd` with zero arguments. # This goal of this is to pick a sensible default for `build.cmd` with zero arguments.
# We believe the most common thing our contributors will work on is C#, so if no other build group was picked, build the C# projects. # We believe the most common thing our contributors will work on is C#, so if no other build group was picked, build the C# projects.

View File

@ -17,6 +17,9 @@ Building ASP.NET Core on Windows requires:
* At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies) * At least 10 GB of disk space and a good internet connection (our build scripts download a lot of tools and dependencies)
* Visual Studio 2017. <https://visualstudio.com> * Visual Studio 2017. <https://visualstudio.com>
* To install the exact required components, run [eng/scripts/InstallVisualStudio.ps1](/eng/scripts/InstallVisualStudio.ps1). This will use VS2017. * To install the exact required components, run [eng/scripts/InstallVisualStudio.ps1](/eng/scripts/InstallVisualStudio.ps1). This will use VS2017.
```ps1
PS> ./eng/scripts/InstallVisualStudio.ps1 -Edition Community
```
* Git. <https://git-scm.org> * Git. <https://git-scm.org>
* (Optional) some optional components, like the SignalR Java client, may require * (Optional) some optional components, like the SignalR Java client, may require
* NodeJS. LTS version of 10.14.2 or newer recommended <https://nodejs.org> * NodeJS. LTS version of 10.14.2 or newer recommended <https://nodejs.org>

View File

@ -1,66 +1,81 @@
<# <#
.SYNOPSIS .SYNOPSIS
Installs or updates Visual Studio on a local developer machine Installs or updates Visual Studio on a local developer machine.
.PARAMETER Update .DESCRIPTION
Update VS to latest version instead of modifying the installation to include new workloads. This installs Visual Studio along with all the workloads required to contribute to this repository.
.PARAMETER Quiet .PARAMETER Edition
Whether to run installer in the background Must be one of these values:
Community
Professional
Enterprise
Selects which 'offering' of Visual Studio to install.
.PARAMETER InstallPath
The location of Visual Studio
.PARAMETER Passive
Run the installer without requiring interaction.
.LINK
https://visualstudio.com
https://github.com/aspnet/AspNetCore/blob/master/docs/BuildFromSource.md
.EXAMPLE
To install VS 2017 Community, run
InstallVisualStudio.ps1 -Edition Community
#> #>
[CmdletBinding(DefaultParameterSetName = 'Default')] [CmdletBinding(DefaultParameterSetName = 'Default')]
param( param(
[switch]$Update, [ValidateSet('Community', 'Professional', 'Enterprise')]
[switch]$Quiet [string]$Edition,
[string]$InstallPath,
[switch]$Passive
) )
if (-not $Edition) {
Write-Host "You must specify a value for the -Edition parameter which selects the kind of Visual Studio to install." -f Red
Write-Host "Run ``Get-Help $PSCommandPath`` for more details." -f Red
Write-Host ""
Write-Host "Example: ./InstallVisualStudio -Edition Community" -f Red
Write-Host ""
exit 1
}
$ErrorActionPreference = 'Stop' $ErrorActionPreference = 'Stop'
Set-StrictMode -Version 1 Set-StrictMode -Version 1
$intermedateDir = "$PSScriptRoot\obj" $intermedateDir = "$PSScriptRoot\obj"
mkdir $intermedateDir -ErrorAction Ignore | Out-Null mkdir $intermedateDir -ErrorAction Ignore | Out-Null
$bootstrapper = "$intermedateDir\vs_enterprise1.exe" $bootstrapper = "$intermedateDir\vsinstaller.exe"
Invoke-WebRequest -Uri 'https://aka.ms/vs/15/release/vs_enterprise.exe' -OutFile $bootstrapper Invoke-WebRequest -Uri "https://aka.ms/vs/15/release/vs_$($Edition.ToLowerInvariant()).exe" -OutFile $bootstrapper
if (-not $InstallPath) {
$InstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\$Edition"
}
$vsJson = "$PSScriptRoot\vs.json"
# no backslashes - this breaks the installer # no backslashes - this breaks the installer
$vsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2017\Enterprise" $InstallPath = $InstallPath.TrimEnd('\')
$arguments = @(
'--installPath', "`"$vsInstallPath`"",
'--in', $vsJson,
'--wait',
'--norestart')
if ($Update) { [string[]] $arguments = @()
$arguments = ,'update' + $arguments
} if (Test-path $InstallPath) {
else { $arguments += 'modify'
$arguments = ,'modify' + $arguments
} }
if ($Quiet) { $arguments += `
$arguments += '--quiet' '--productId', "Microsoft.VisualStudio.Product.$Edition", `
'--installPath', "`"$InstallPath`"", `
'--in', "$PSScriptRoot\vs.json", `
'--norestart'
if ($Passive) {
$arguments += '--passive'
} }
Write-Host "Running '$bootstrapper $arguments' on $(hostname)" Write-Host ""
$process = Start-Process -FilePath $bootstrapper ` Write-Host "Installing Visual Studio 2017 $Edition" -f Magenta
-ArgumentList $arguments ` Write-Host ""
-Verb runas ` Write-Host "Running '$bootstrapper $arguments'"
-PassThru `
-ErrorAction Stop
Write-Host "pid = $($process.Id)"
Wait-Process -InputObject $process
Write-Host "exit code = $($process.ExitCode)"
# https://docs.microsoft.com/en-us/visualstudio/install/use-command-line-parameters-to-install-visual-studio#error-codes & $bootstrapper @arguments
if ($process.ExitCode -eq 3010) {
Write-Warning "Agent $(hostname) requires restart to finish the VS update"
}
elseif ($process.ExitCode -eq 5007) {
Write-Error "Operation was blocked - the computer does not meet the requirements"
}
elseif (($process.ExitCode -eq 5004) -or ($process.ExitCode -eq 1602)) {
Write-Error "Operation was canceled"
}
elseif ($process.ExitCode -ne 0) {
Write-Error "Installation failed on $(hostname) for unknown reason"
}

View File

@ -1,7 +1,6 @@
{ {
"channelUri": "https://aka.ms/vs/15/release/channel", "channelUri": "https://aka.ms/vs/15/release/channel",
"channelId": "VisualStudio.15.Release", "channelId": "VisualStudio.15.Release",
"productId": "Microsoft.VisualStudio.Product.Enterprise",
"includeRecommended": false, "includeRecommended": false,
"addProductLang": [ "addProductLang": [
"en-US" "en-US"