Created
September 13, 2019 21:23
-
-
Save oising/028c8182e1940d3f7e661dabec4f673b to your computer and use it in GitHub Desktop.
Allow "Developer Powershell for VS 2019" environment to be bootstrapped within powershell core / pwsh
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
[cmdletbinding()] | |
param([switch]$Preview) | |
# vswhere will reliably locate visual studio installations | |
if (!(gcm vswhere)) { | |
# https://chocolatey.org/ | |
if (gcm choco) { | |
choco install vswhere -y | |
} | |
else { | |
# https://github.com/microsoft/vswhere/wiki/Installing | |
write-warning "VSWhere.exe not found. Please install it in your path." | |
exit | |
} | |
} else { | |
write-verbose "vswhere found!" | |
} | |
$prerelease = $(if ($preview.ispresent) { "-prerelease" }) | |
$vsconfig = $(convertfrom-json ((iex "vswhere -latest $prerelease -format json") -join "")) | |
$instanceId = $vsconfig.instanceid | |
$bootstrapper = join-path $vsconfig.installationPath "Common7\Tools\Microsoft.VisualStudio.DevShell.dll" | |
write-verbose "Bootstrapper path: $bootstrapper" | |
if (test-path $bootstrapper) { | |
import-module $bootstrapper | |
# this cmdlet throws an exception about telemetry (boo-hoo) but succeeds in its main task | |
try { enter-vsdevshell $instanceId } catch {} | |
} else { | |
write-warning "VS DevShell library not found for $($vsconfig.installationname). Try using -Preview switch." | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment