InstallVisualStudio.ps1 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <#
  2. .SYNOPSIS
  3. Installs or updates Visual Studio on a local developer machine.
  4. .DESCRIPTION
  5. This installs Visual Studio along with all the workloads required to contribute to this repository.
  6. .PARAMETER InstallPath
  7. The location of Visual Studio
  8. .PARAMETER Passive
  9. Run the installer without requiring interaction.
  10. .LINK
  11. https://visualstudio.com
  12. https://github.com/aspnet/AspNetCore/blob/master/docs/BuildFromSource.md
  13. .EXAMPLE
  14. To install VS 2019 Preview, run this command in PowerShell:
  15. .\InstallVisualStudio.ps1
  16. #>
  17. [CmdletBinding(DefaultParameterSetName = 'Default')]
  18. param(
  19. # TODO - once VS 2019 16.0 RTM is released, make this a parameter again
  20. # .PARAMETER Edition
  21. # Must be one of these values:
  22. # Community
  23. # Professional
  24. # Enterprise
  25. # Selects which 'offering' of Visual Studio to install.
  26. # [ValidateSet('Community', 'Professional', 'Enterprise')]
  27. # [string]$Edition,
  28. [string]$InstallPath,
  29. [switch]$Passive
  30. )
  31. # VS previews are only available publicly as 'Enterprise' versions. They should be available to the community to use without a paid license.
  32. $Edition = 'Enterprise'
  33. if (-not $Edition) {
  34. Write-Host "You must specify a value for the -Edition parameter which selects the kind of Visual Studio to install." -f Red
  35. Write-Host "Run ``Get-Help $PSCommandPath`` for more details." -f Red
  36. Write-Host ""
  37. Write-Host "Example: ./InstallVisualStudio -Edition Community" -f Red
  38. Write-Host ""
  39. exit 1
  40. }
  41. $ErrorActionPreference = 'Stop'
  42. Set-StrictMode -Version 1
  43. $intermedateDir = "$PSScriptRoot\obj"
  44. mkdir $intermedateDir -ErrorAction Ignore | Out-Null
  45. $bootstrapper = "$intermedateDir\vsinstaller.exe"
  46. $ProgressPreference = 'SilentlyContinue' # Workaround PowerShell/PowerShell#2138
  47. Invoke-WebRequest -Uri "https://aka.ms/vs/16/pre/vs_$($Edition.ToLowerInvariant()).exe" -OutFile $bootstrapper
  48. if (-not $InstallPath) {
  49. # $InstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\$Edition"
  50. $InstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Preview"
  51. }
  52. # no backslashes - this breaks the installer
  53. $InstallPath = $InstallPath.TrimEnd('\')
  54. [string[]] $arguments = @()
  55. if (Test-path $InstallPath) {
  56. $arguments += 'modify'
  57. }
  58. $arguments += `
  59. '--productId', "Microsoft.VisualStudio.Product.$Edition", `
  60. '--installPath', "`"$InstallPath`"", `
  61. '--in', "$PSScriptRoot\vs.json", `
  62. '--norestart'
  63. if ($Passive) {
  64. $arguments += '--passive'
  65. }
  66. Write-Host ""
  67. Write-Host "Installing Visual Studio 2019 $Edition" -f Magenta
  68. Write-Host ""
  69. Write-Host "Running '$bootstrapper $arguments'"
  70. & $bootstrapper @arguments