Kondr1 avatar image
0 Votes"
Kondr1 asked ·

Microsoft.VisualStudio.DevShell documentation

I can't found any documentation about load dev shell in powershell comand line. But for cmd it exist

We have only one post in ms blog about that.

Why we have to use some InstanceId for start Enter-VsDevShell ?
Which else comands exist in Microsoft.VisualStudio.DevShell module?
Why you don't distribute this module through PSGallery?

· 2
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

The ”windows-server-powershell“ tag focuses on questions about explanation and correction of commands, advice for PowerShell scripts, and troubleshooting PowerShell-related issues.
Since your issue is more related to Visual Studio, I have removed the "windows-server-powershell" tag. You can send feedback via the Developer Community.

1 Vote 1 ·

1 Answer

cooldadtx avatar image
0 Votes"
cooldadtx answered ·

While it will be nice when the dev command prompt supports Powershell as well part of the issue is which PS version to support. PS 5 is on all Windows machines but it is old and PS 7.1 is preferable. But some of the behavior is different so MS would need to create a script for either version which adds more effort.

However you can still call the existing dev command prompt from PS. That is what I do myself. I have my own "Dev command prompt" which is Powershell. Amongst other things like setting up my custom path variables it calls into the VS command prompt to initialize it as well. Therefore I have all the features of the command line shell plus my own customizations.

Here's the subset of the PS that I use to set up my environment.

function InvokeCommandFile 
        [Parameter(Mandatory=$true)][string] $filePath,
        [string] $arguments
   $tempFile = [IO.Path]::GetTempFileName()

   ## Store the output of cmd.exe.  We also ask cmd.exe to output
   ## the environment table after the batch file completes
   cmd /c " `"$filePath`" $arguments && set > `"$tempFile`" "

   ## Go through the environment variables in the temp file.
   ## For each of them, set the variable in our local environment.
   Get-Content $tempFile | Foreach-Object {
    if($_ -match "^(.*?)=(.*)$")
        Set-Content "env:\$($matches[1])" $matches[2]

   Remove-Item $tempFile

# Call the VS command prompt script
$env:VSTOOLS='C:\<path to VS>\Common7\Tools'
InvokeCommandFile "$env:VSTOOLS\VSDevCmd.bat"

The path to VS depends upon where you install it so you'll need to adjust. The batch script that MS runs mostly sets up envvars but since that is being run in a separate session we have to hoist the variables into PS. There may be an easier way to do this in newer PS versions but the version I use (copied from somebody else) for both PS 5 and 7.1 outputs the script results to a temp file and then finds the env variables and sets them in the current PS session. I've been using this for years without issues but there could be an oddball case it doesn't work for.

· 2 ·
10 |1000 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

It's not actually answer on my question. Microsoft declare PS support here, but not documenting it. If it exists we are need to know how it use

0 Votes 0 ·

There are many things in VS that are supported but not documented. It is a complex app. Issues with documentation should be posted to the microsoft docs site so the docs team can take a look at it.

0 Votes 0 ·