Mastodon
//Ris Adams;

Loading Visual Studio environment in your default PowerShell profile

Cover image for Loading Visual Studio environment in your default PowerShell profile.

As a developer, you may want to load the Visual Studio environment in your default PowerShell profile. This is useful for debugging and developing.

If you aren’t already aware, the easiest way to edit your profile is by using the profile variable. I use vscode, but you are free to use your favorite editor of choice.

code $PROFILE

The easiest way to do this used to be by calling VsDevCmd.bat from the tools directory. However, this can be fragile (and broken as of 2022-06-03). The below script is a bit more resilient and will load more quickly.

Update - 2020-06-07, corrected an issue where the profile wasn’t restoring the current directory. added a push/pop

Updated profile script

# use the vswhere command to find the location of Visual Studio, then append the tools path
$vspath = &"C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationpath
$tools = $vspath + "\Common7\Tools"

## launch the Visual Studio environment, and return to the current directory
Push-Location .
Import-Module $tools\Microsoft.VisualStudio.DevShell.dll
Enter-VsDevShell -VsInstallPath $VSPath
Pop-Location
§