Skip to content

Instantly share code, notes, and snippets.

@applejag
Created March 16, 2020 17:11
Show Gist options
  • Save applejag/fd31560ed9b5bbede69d72269c1209ad to your computer and use it in GitHub Desktop.
Save applejag/fd31560ed9b5bbede69d72269c1209ad to your computer and use it in GitHub Desktop.
Visual Studio Developer PowerShell in Windows Terminal

Just a small profile template to get the Visual Studio Developer command prompt environment, but in PowerShell, but in the Windows Terminal. Cake on cake 🍰

Profile installation

Add the following profile to your Windows Terminal profiles.json file.

Old profiles syntax

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "profiles": [
        {
            "guid": "{dd241469-5e90-55ff-816c-914203bdc6ea}",
            "name": "Dev Cmd Prompt VS 2019",
            "commandline": "powershell.exe -noe -c \".{$vsInstallPath=&\"\"\"${Env:ProgramFiles(x86)}\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\"\" -Property InstallationPath;Import-Module \"\"\"$vsInstallPath\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\";function prompt(){Write-Host \"\"\"VS Dev Prompt $Env:VSCMD_VER \"\"\" -NoNewline -ForegroundColor White;Write-Host $(pwd) -NoNewline;Write-Host \"\"\">\"\"\" -NoNewline -ForegroundColor White;return \"\"\" \"\"\"}Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation}\"",
            "hidden": false,
            "startingDirectory": ".",
            "acrylicOpacity" : 0.75,
            "useAcrylic" : true
        }
    ]
}

New profiles syntax

What's nice about the new format is that you can supply default values, such as "useAcrylic": true for all profiles.

{
    "$schema": "https://aka.ms/terminal-profiles-schema",

    "profiles": {
        "defaults": {
        },
        "list": [
            {
                "guid": "{dd241469-5e90-55ff-816c-914203bdc6ea}",
                "name": "Dev Cmd Prompt VS 2019",
                "commandline": "powershell.exe -noe -c \".{$vsInstallPath=&\"\"\"${Env:ProgramFiles(x86)}\\Microsoft Visual Studio\\Installer\\vswhere.exe\"\"\" -Property InstallationPath;Import-Module \"\"\"$vsInstallPath\\Common7\\Tools\\Microsoft.VisualStudio.DevShell.dll\"\"\";function prompt(){Write-Host \"\"\"VS Dev Prompt $Env:VSCMD_VER \"\"\" -NoNewline -ForegroundColor White;Write-Host $(pwd) -NoNewline;Write-Host \"\"\">\"\"\" -NoNewline -ForegroundColor White;return \"\"\" \"\"\"}Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation}\"",
                "hidden": false,
                "startingDirectory": ".",
                "acrylicOpacity" : 0.75,
                "useAcrylic" : true
            }
        ]
    }
}

Explanation

The commandLine property in the profile holds the following script wrapped inside a powershell.exe -noe -c call:

.{
    $vsInstallPath = &"${Env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -Property InstallationPath
    Import-Module "$vsInstallPath\Common7\Tools\Microsoft.VisualStudio.DevShell.dll"
    
    function prompt() {
        Write-Host "VS Dev Prompt $Env:VSCMD_VER " -NoNewline -ForegroundColor White
        Write-Host $(pwd) -NoNewline
        Write-Host ">" -NoNewline -ForegroundColor White
        return " "
    }
    
    Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment