Created
December 2, 2021 08:04
-
-
Save bhardwajs/30a6a2eb608f3f6ae8366def64edd372 to your computer and use it in GitHub Desktop.
Powershell scrip to launch Visual Studio
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<# | |
.SYNOPSIS | |
Launch Visual Studio | |
.DESCRIPTION | |
Use this script to launch Visual Studio. | |
.PARAMETER release | |
Which release of VS to use - takes values 16 and 17. Defaults to 17 which is VS 2022. | |
.PARAMETER targetArch | |
Target architecture - takes values 'x64' and 'x86'. Defaults to x64. | |
.PARAMETER onlyProd | |
Boolean value that decides whether to launch only production VS. Defaults to false which enables loading preview versions too. | |
.EXAMPLE | |
launch_vs.ps1 -release 17 -targetArch x64 -onlyProd | |
.EXAMPLE | |
launch_vs.ps1 16 | |
Launches VS 2019 for targeting x64. | |
#> | |
Param( | |
[Parameter(Position=0)] | |
[ValidateSet('16', '17')] | |
[String] | |
$release = 17, | |
[Parameter(Position=1)] | |
[ValidateSet('x64', 'x86')] | |
[String] | |
$targetArch = 'x64', | |
[Parameter(Position=2)] | |
[switch] | |
$onlyProd = $false | |
) | |
$ErrorActionPreference = 'Stop' | |
Write-Host("Launching Visual Studio version ${release} targeting ${targetArch}.") | |
if($onlyProd) | |
{ | |
Write-Host("Limiting to production version.") | |
} | |
switch -Exact ($release) | |
{ | |
'16' | |
{ | |
$vsVersion = '[16.0,17.0)' | |
} | |
default | |
{ | |
$vsVersion = '[17.0,18.0)' | |
} | |
} | |
Push-Location . | |
$vsPath = &(Join-Path ${Env:\ProgramFiles(x86)} '\Microsoft Visual Studio\Installer\vswhere.exe') ` | |
$($onlyProd ? '' : '-prerelease') ` | |
-latest ` | |
-version ${vsVersion} ` | |
-property installationpath; | |
Write-Host($vsPath) | |
Import-Module (Join-Path $vsPath 'Common7\Tools\Microsoft.VisualStudio.DevShell.dll'); | |
Enter-VsDevShell ` | |
-VsInstallPath $vsPath ` | |
-SkipAutomaticLocation ` | |
-DevCmdArguments "-arch=${targetArch} -host_arch=x64"; | |
Pop-Location | |
$Env:WindowsSdkDir = `Get-ChildItem 'HKLM:\SOFTWARE\Microsoft\Windows Kits\' ` | |
| Get-ItemPropertyValue -Name KitsRoot10 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment