暂无描述

install-vs-features.ps1 2.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. param (
  2. [Parameter(Mandatory=$true)]
  3. [string[]] $Components,
  4. [uri] $InstallerUri = "https://download.visualstudio.microsoft.com/download/pr/c4fef23e-cc45-4836-9544-70e213134bc8/1ee5717e9a1e05015756dff77eb27d554a79a6db91f2716d836df368381af9a1/vs_Enterprise.exe",
  5. [string] $VsInstaller = "${env:System_DefaultWorkingDirectory}\vs_Enterprise.exe",
  6. [string] $VsInstallOutputDir = "${env:System_DefaultWorkingDirectory}\vs",
  7. [System.IO.FileInfo] $VsInstallPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\2019\Enterprise",
  8. [System.IO.FileInfo] $VsInstallerPath = "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer",
  9. [switch] $Collect = $false,
  10. [switch] $Cleanup = $false,
  11. [switch] $UseWebInstaller = $false
  12. )
  13. $Components | ForEach-Object {
  14. $componentList += '--add', $_
  15. }
  16. $LocalVsInstaller = "$VsInstallerPath\vs_installershell.exe"
  17. $UseWebInstaller = $UseWebInstaller -or -not (Test-Path -Path "$LocalVsInstaller")
  18. if ($UseWebInstaller) {
  19. Write-Host "Downloading web installer..."
  20. Invoke-WebRequest -Method Get `
  21. -Uri $InstallerUri `
  22. -OutFile $VsInstaller
  23. New-Item -ItemType directory -Path $VsInstallOutputDir
  24. Write-Host "Running web installer to download requested components..."
  25. Start-Process `
  26. -FilePath "$VsInstaller" `
  27. -ArgumentList ( `
  28. '--layout', "$VsInstallOutputDir",
  29. '--wait',
  30. '--norestart',
  31. '--quiet' + `
  32. $componentList
  33. ) `
  34. -Wait `
  35. -PassThru
  36. Write-Host "Running downloaded VS installer to add requested components..."
  37. Start-Process `
  38. -FilePath "$VsInstallOutputDir\vs_Enterprise.exe" `
  39. -ArgumentList (
  40. 'modify',
  41. '--installPath', "`"$VsInstallPath`"" ,
  42. '--wait',
  43. '--norestart',
  44. '--quiet' + `
  45. $componentList
  46. ) `
  47. -Wait `
  48. -PassThru `
  49. -OutVariable returnCode
  50. if ($Cleanup) {
  51. Write-Host "Cleaning up..."
  52. Remove-Item -Path $VsInstaller
  53. Remove-Item -Path $VsInstallOutputDir -Recurse
  54. }
  55. } else {
  56. Write-Host "Running local installer to add requested components..."
  57. Start-Process `
  58. -FilePath "$LocalVsInstaller" `
  59. -ArgumentList (
  60. 'modify',
  61. '--installPath', "`"$VsInstallPath`"" ,
  62. '--norestart',
  63. '--quiet' + `
  64. $componentList
  65. ) `
  66. -Wait `
  67. -OutVariable returnCode
  68. }
  69. if ($Collect) {
  70. Invoke-WebRequest -Method Get `
  71. -Uri 'https://download.microsoft.com/download/8/3/4/834E83F6-C377-4DCE-A757-69A418B6C6DF/Collect.exe' `
  72. -OutFile ${env:System_DefaultWorkingDirectory}\Collect.exe
  73. # Should generate ${env:Temp}\vslogs.zip
  74. Start-Process `
  75. -FilePath "${env:System_DefaultWorkingDirectory}\Collect.exe" `
  76. -Wait `
  77. -PassThru
  78. New-Item -ItemType Directory -Force ${env:System_DefaultWorkingDirectory}\vslogs
  79. Expand-Archive -Path ${env:TEMP}\vslogs.zip -DestinationPath ${env:System_DefaultWorkingDirectory}\vslogs\
  80. Write-Host "VC versions after installation:"
  81. Get-ChildItem -Name "$VsInstallPath\VC\Tools\MSVC\"
  82. }