Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Developer PowerShell and Developer Command Prompt Generator #3821

Closed
aetos382 opened this issue Dec 3, 2019 · 30 comments · Fixed by #7774
Closed

Add Developer PowerShell and Developer Command Prompt Generator #3821

aetos382 opened this issue Dec 3, 2019 · 30 comments · Fixed by #7774
Labels
Area-Extensibility A feature that would ideally be fulfilled by us having an extension model. Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.

Comments

@aetos382
Copy link

aetos382 commented Dec 3, 2019

Description of the new feature/enhancement

Developer PowerShell and Developer Command Prompt are installed with VS 2019.
I’d like to add these profiles automatically when installing Windows Terminal on a machine with VS 2019 installed.
I think this is useful for developers using Visual Studio.

@aetos382 aetos382 added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Dec 3, 2019
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Dec 3, 2019
@zadjii-msft zadjii-msft added Area-Extensibility A feature that would ideally be fulfilled by us having an extension model. Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Product-Terminal The new Windows Terminal. and removed Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. labels Dec 3, 2019
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Dec 3, 2019
@DHowett-MSFT DHowett-MSFT removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Dec 5, 2019
@DHowett-MSFT DHowett-MSFT added this to the Terminal Backlog milestone Dec 5, 2019
@ffes
Copy link

ffes commented Jan 8, 2020

Maybe they should just be added to https://github.com/microsoft/terminal/blob/master/doc/user-docs/ThirdPartyToolProfiles.md

This could be the VS 2019 CMD, Community Edition

{
  "commandline": "cmd.exe /k \"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/VsDevCmd.bat\"",
  "icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png",
  "name": "Developer CMD for VS 2019"
},

And this for the VS 2019 Powershell, Community Edition

{
  "commandline": "powershell.exe -noe -c \"&{Import-Module \"\"\"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"\"\"; Enter-VsDevShell 9be17693}\"",
  "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
  "name": "Developer PowerShell for VS 2019"
},

Both based on the start menu entries added by VS setup. They work fine for me.

@ghost
Copy link

ghost commented Jan 16, 2020

They work fine for me.

For me Developer PowerShell for VS 2019 is generating an error on startup:

Enter-VsDevShell : 9be17693
No linha:1 caractere:132
+ ... ools/Microsoft.VisualStudio.DevShell.dll"; Enter-VsDevShell 9be17693}
+                                                ~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidArgument: (:) [Enter-VsDevShell], ItemNotFoundException
    + FullyQualifiedErrorId : VsInstallationNotFound,Microsoft.VisualStudio.DevShell.Commands.EnterVsDevShellCommand

@ghost
Copy link

ghost commented Jan 16, 2020

Gotcha. Actually the profile provided by @ffes work as expected, since you change the identifier after Enter-VsDevShell to the identifier in Developer PowerShell for VS 2019 shortcut. Mine, for example, is 4704b565.

image

@aetos382
Copy link
Author

Yes. If you want to add a profile for yourself, you need to get the instance ID from the shortcut in the start menu and set it on the command line.
Windows Terminal has a mechanism to dynamically generate profiles.
I think the VSSetup PowerShell module will help implement Developer Console Profile Generator.
https://github.com/microsoft/vssetup.powershell/tree/develop/src/VSSetup.PowerShell

@Greyze
Copy link

Greyze commented May 22, 2020

I have this setup;

image

I had to create the icon besides just adding the profile. It would be great if all the dev prompts with appropriate icons were added by default (VS2017, VS2019 etc).

@Hummer311
Copy link

For the Powershell configuration, I've used the following. So far, so good.

,
{
    "commandline": "powershell.exe -noe -c \"&{ install-module vssetup -Scope currentuser; $i=(get-vssetupinstance); $i; Import-Module \"\"\"$($i.InstallationPath)/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"\"\"; Enter-VsDevShell $i.Instanceid;}\"",
    "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png",
    "name": "VS2019 Powershell"
}

@Evangelink
Copy link
Member

The following link https://docs.microsoft.com/visualstudio/install/tools-for-managing-visual-studio-instances helped me to find the instance ID (I have been using the vswhere command)

@akunzai
Copy link

akunzai commented Jun 30, 2020

The Developer PowerShell profile that using vswhere command.

{
  "name": "Developer PowerShell",
  "commandline": "powershell.exe -NoExit -Command \"&{ $vsInstallPath=& \"${env:ProgramFiles(x86)}/'Microsoft Visual Studio'/Installer/vswhere.exe\" -prerelease -latest -property installationPath; Import-Module \"$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation }\"",
  "icon": "ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png"
}

@patrikhuber
Copy link

patrikhuber commented Jul 14, 2020

Hi,

I'm extremely interested in this. How can I open an "x64 Native Tools Command Prompt for VS 2019" with Windows Terminal? Note that this is slightly (but importantly) different from the "Developer Command Prompt for VS 2019".

If that was available from the Windows Terminal dropdown menu (with a nice icon) like in @Greyze's screenshot above, that would be even more amazing.

@huoyaoyuan
Copy link
Contributor

@patrikhuber You can right click the .lnk in start menu, and view what parameters it uses in the details, and compare between them.

@patrikhuber
Copy link

@huoyaoyuan: It shows Target: as:

%comspec% /k "C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\Auxiliary\Build\vcvars64.bat"

@patrikhuber
Copy link

Modifying the snippet posted here https://github.com/microsoft/terminal/blob/master/doc/user-docs/ThirdPartyToolProfiles.md#developer-command-prompt-for-visual-studio works for me:

{
	"name": "x64 Native Tools Command Prompt for VS 2019",
	"commandline": "%comspec% /k \"C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Auxiliary/Build/vcvars64.bat\"",
	"startingDirectory": "%USERPROFILE%",
	"icon": "ms-appx:///ProfileIcons/{0caa0dad-35be-5f56-a8ff-afceeeaa6101}.png"
}

Thank you!

@patrikhuber
Copy link

patrikhuber commented Jul 18, 2020

Is there any way of setting this to the Visual Studio 2019 icon? I tried this, but it (expectedly) doesn't work:

"icon": "C:\\Program Files (x86)\\Microsoft Visual Studio\\2019\\Community\\Common7\\IDE\\devenv.exe"

Do I have to extract the icon from the .exe using a 3rd-party tool, or is there an easier way?

The docs don't mention anything https://docs.microsoft.com/en-us/windows/terminal/customize-settings/profile-settings#icon.

@Greyze
Copy link

Greyze commented Jul 18, 2020

Sadly there isn't a convenient way for that to automatically be added. I had to work around it.

I downloaded the VS2019 icon from the microsoft website. I'll add it here for you:

vs2019-32

I then dropped that image file into the terminals installation directory/RoamingState folder. Since I installed Terminal from the MS Store my folder is:
C:\Users\*\AppData\Local\Packages\Microsoft.WindowsTerminal_8wekyb3d8bbwe\RoamingState

Lastly in the settings.json, i added the icon with this path:
"icon": "ms-appdata:///roaming/vs2019-32.png"

You should be good to go now. Obviously tweak the paths to your preferred choice. For clarity heres my whole settings block for VS2019 which gives you the terminal you saw in my image above:

{
    "acrylicOpacity": 0.75,
    "commandline": "cmd.exe /k \"C://Program Files (x86)//Microsoft Visual Studio//2019//Enterprise//Common7//Tools//VsDevCmd.bat\"",
    "guid": "{184f02e0-01c0-495e-9d97-b2467ec16958}",
    "historySize": 9001,
    "icon": "ms-appdata:///roaming/vs2019-32.png",
    "name": "Developer Command Prompt for VS2019",
    "startingDirectory": "%USERPROFILE%",
    "useAcrylic": true
},

@patrikhuber
Copy link

@Greyze Thanks a lot, that's great! :)

@patrikhuber
Copy link

One can also extract the .ico from devenv.exe, with Visual Studio, without any third party tool. Visual Studio => Open => File... => devenv.exe => expand "Icon" => right-click on the one you want, "Export". The .ico also works as "icon" for Windows Terminal.

@ghost ghost added the In-PR This issue has a related PR label Sep 29, 2020
@ghost ghost added In-PR This issue has a related PR and removed In-PR This issue has a related PR labels Dec 15, 2020
@ANF-Studios
Copy link

Alright, so this is my configuration, works like a charm:

{
    "guid": "{1748ecca-abdd-4aa4-bcc4-9fca0d045be5}",
    "name": "VS Developer PowerShell",
    "commandline": "powershell.exe -NoExit -Command \"&{ $vsInstallPath=& \"${env:ProgramFiles(x86)}/'Microsoft Visual Studio'/Installer/vswhere.exe\" -prerelease -latest -property installationPath; Import-Module \"$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation }\"",
    "icon": "https://devblogs.microsoft.com/wp-content/uploads/sites/4/2019/06/vs-for-mac-logo-caption2.png",
    "startingDirectory": "%USERPROFILE%",
    "hidden": false
},

I believe this will work for other editions as well. And for the icon, it gets cached the first time it's downloaded, I think.
image

It will get added soon, but, here you go anyways.

@Robertschv
Copy link

Alright, so this is my configuration, works like a charm:

{
    "guid": "{1748ecca-abdd-4aa4-bcc4-9fca0d045be5}",
    "name": "VS Developer PowerShell",
    "commandline": "powershell.exe -NoExit -Command \"&{ $vsInstallPath=& \"${env:ProgramFiles(x86)}/'Microsoft Visual Studio'/Installer/vswhere.exe\" -prerelease -latest -property installationPath; Import-Module \"$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation }\"",
    "icon": "https://devblogs.microsoft.com/wp-content/uploads/sites/4/2019/06/vs-for-mac-logo-caption2.png",
    "startingDirectory": "%USERPROFILE%",
    "hidden": false
},

I believe this will work for other editions as well. And for the icon, it gets cached the first time it's downloaded, I think.
image

It will get added soon, but, here you go anyways.

What did you do? The "commandline" doesn't work in my PowerShell
The PowerShell doesn't like the "&" of $vsInstallPath=&

@ANF-Studios
Copy link

@Robertschv, that doesn't provide much detail for me to diagnose the cause of the issue, but from my experience, if you're using ui to do this, it jut won't work.

@Robertschv
Copy link

@Robertschv, that doesn't provide much detail for me to diagnose the cause of the issue, but from my experience, if you're using ui to do this, it jut won't work.

This is what happens

Captura de pantalla de 2021-03-18 23-33-40

What to try this command in a Powershell, is there a way? I imagine is somewhat like this -->
&{ $vsInstallPath=& \"${env:ProgramFiles(x86)}/'Microsoft Visual Studio'/Installer/vswhere.exe\" -prerelease -latest -property installationPath; Import-Module \"$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation }

@ANF-Studios
Copy link

ANF-Studios commented Mar 19, 2021

Oh Rob, that's not for normal PowerShell instances. I don't see the confusion either, it's easily translatable. If you just prefer hard coding though:

$vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\<Year>\<Edition>\" # Declare VS' installation path.
Import-Module "$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll" # Import the dll which allows access to VS' Developer PowerShell functions.
# Great, you now have access to it!
Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation # Use this to boot it up.

However, I do recommend that you learn PowerShell as it'll help you a lot, automation will only make life easier.

Quick side note: You can also launch this batch file:

Batch file

@Robertschv
Copy link

Awesome, it worked!
Yes I am learning more about powershell
Thank you!

@SheepReaper
Copy link

This also works with PS Core if installed (replace powershell.exe with pwsh)
Also unrelated, but helpful: Use -DevCmdArguments to select the desired toolchain: (I'm doing native compilation by default)
If you don't specify, it selects x86, x86

{
    "guid": "{d064db1b-5bf4-4497-98df-220e5b8da170}",
    "hidden": false,
    "name": "Developer PS (2019)",
    "commandline": "pwsh -noe -c \"&{ $vsInstallPath=& \"${env:ProgramFiles(x86)}/'Microsoft Visual Studio'/Installer/vswhere.exe\" -prerelease -latest -property installationPath; Import-Module \"$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll\"; Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation -DevCmdArguments '-arch=amd64 -host_arch=amd64'}\"",
    "icon": "https://devblogs.microsoft.com/wp-content/uploads/sites/4/2019/06/vs-for-mac-logo-caption2.png",
    "startingDirectory": "%USERPROFILE%"
}

@maxnoe
Copy link

maxnoe commented May 20, 2021

With the new graphical settings editor, this is what I had to put into the command line field:

pwsh.exe -NoExit -Command " &{ $vsInstallPath=& "${env:ProgramFiles(x86)}\'Microsoft Visual Studio'\Installer\vswhere.exe" -prerelease -latest -property installationPath; Import-Module "$vsInstallPath/Common7/Tools/Microsoft.VisualStudio.DevShell.dll"; Enter-VsDevShell -VsInstallPath $vsInstallPath -SkipAutomaticLocation }"

@ANF-Studios
Copy link

ANF-Studios commented May 20, 2021

One thing I want to point out is that this will bring up the old PowerShell 5, if you want the new PowerShell Core 7, with multiple enhancements (which I do recommend), simply just change the powershell.exe part in whichever startup command you use to pwsh.exe, just make sure that it indeed is installed.

If you want to try out the new PowerShell Core, please visit the releases page. Fun fact; it's not only open source, but also cross-platform.

To verify that, run:

Get-Host | Select-Object Version

@maxnoe
Copy link

maxnoe commented May 21, 2021

This is a bit OT, but maybe you have an idea: when building a python binary wheel (using a cython extension) it works fine in the normal powershell (using the MSVC compiler) but in the "Developer Powershell" it fails to link against the python library and I get undefined symbols:

fibonacci.obj : error LNK2001: Unresolved external symbol "__imp__PyObject_SetAttr".
fibonacci.obj : error LNK2001: Unresolved external symbol "__imp__PyUnicode_InternFromString".
fibonacci.obj : error LNK2001: Unresolved external symbol "__imp__PyOS_snprintf".
fibonacci.obj : error LNK2001: Unresolved external symbol "__imp__PyThreadState_Get"
...

Any idea why explicitly opening the developer shell has this effect?

@orcmid
Copy link

orcmid commented Jul 22, 2021

@ANF-Studios :> Oh Rob, that's not for normal PowerShell instances. I don't see the confusion either, it's easily translatable. If you just prefer hard coding though:

$vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\<Year>\<Edition>\" # Declare VS' installation path.

I have a tangential concern that is also related to the discussion about developer commands.

Once upon a time in a galaxy far away, I could create a batch script that would discover the location of the Build Tools either for the latest version of VS or any specified older version. That was because the settings had a definition that could be discovered using the user settings that could be probed for in a .bat file.

Then that went away. It stopped some work of mine to provide simple compiles for reproducing builds by folks just getting into working on open-source Windows projects conducted on GitHub. I did not require use of Visual Studio, and one could do fine with a Community Edition or by just installing the Build Tools (and VS Code in all the editor examples).

I see that the start menu entries for later editions do have the entries for a few developer environments, and I had decided to find a way to mine that (or require it as a prerequisite before running my compile and other utility scripts).

I thought this @ANF-Studios example might lead to treasure. However, on my machine

C:/Program Files (x86)/Microsoft Visual Studio/ is empty except for folder Installer, although vswhere.exe in there might be handy. On the other hand, the Start Page "Developer Command Prompt for Visual Studio 2019" does the requisite magic, giving me

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.6.0
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

D:\crea\VSBuildTools\2019>

and I would be a happy camper if I could wind my way through that link to the batch files I want to run to set up a compile environment that my user/student/enthusiast has managed to install. (You can also see that I have the VS Build Tools installed elsewhere and that should not be a barrier.) Running this is a lot more than just setting VS160CMNTOOLS, which is all I need, although VSINSTALLDIR would also work as a starting point.

I am inspired to did deeper into this for my own purposes. I suspect I have also indicated that some of the presumed directory locations might not work for everyone.

@SheepReaper
Copy link

@ANF-Studios :> Oh Rob, that's not for normal PowerShell instances. I don't see the confusion either, it's easily translatable. If you just prefer hard coding though:

$vsInstallPath = "C:\Program Files (x86)\Microsoft Visual Studio\<Year>\<Edition>\" # Declare VS' installation path.

I have a tangential concern that is also related to the discussion about developer commands.

Once upon a time in a galaxy far away, I could create a batch script that would discover the location of the Build Tools either for the latest version of VS or any specified older version. That was because the settings had a definition that could be discovered using the user settings that could be probed for in a .bat file.

Then that went away. It stopped some work of mine to provide simple compiles for reproducing builds by folks just getting into working on open-source Windows projects conducted on GitHub. I did not require use of Visual Studio, and one could do fine with a Community Edition or by just installing the Build Tools (and VS Code in all the editor examples).

I see that the start menu entries for later editions do have the entries for a few developer environments, and I had decided to find a way to mine that (or require it as a prerequisite before running my compile and other utility scripts).

I thought this @ANF-Studios example might lead to treasure. However, on my machine

C:/Program Files (x86)/Microsoft Visual Studio/ is empty except for folder Installer, although vswhere.exe in there might be handy. On the other hand, the Start Page "Developer Command Prompt for Visual Studio 2019" does the requisite magic, giving me

**********************************************************************
** Visual Studio 2019 Developer Command Prompt v16.6.0
** Copyright (c) 2020 Microsoft Corporation
**********************************************************************

D:\crea\VSBuildTools\2019>

and I would be a happy camper if I could wind my way through that link to the batch files I want to run to set up a compile environment that my user/student/enthusiast has managed to install. (You can also see that I have the VS Build Tools installed elsewhere and that should not be a barrier.) Running this is a lot more than just setting VS160CMNTOOLS, which is all I need, although VSINSTALLDIR would also work as a starting point.

I am inspired to did deeper into this for my own purposes. I suspect I have also indicated that some of the presumed directory locations might not work for everyone.

MS has moved to using the visual studio installer for all editions of VS as well as the build tools. A development novice would have to work hard to not use the VS installer to get their kits. The presumption here is that you will have vswhere available. For most novices you can also assume that things are installed in default locations. If you have the presence of mind to specify alternate install locations for things, then it's on you to know you have to locate vswhere somewhere else.

There's no magic bullet to locating installation directories unless you count wmi to at least find the VS Installer, but that seems like work to handle niche cases and not even all of them. Nevertheless, such a script to first locate vswhere and then use it, might have some value, but we've strayed from the topic of Windows Terminal and the simple JSON it provides to create new environments.

@ghost ghost added In-PR This issue has a related PR and removed In-PR This issue has a related PR labels Sep 3, 2021
@ghost ghost added Needs-Tag-Fix Doesn't match tag requirements and removed In-PR This issue has a related PR labels Sep 15, 2021
DHowett pushed a commit that referenced this issue Sep 15, 2021
This commit adds dynamic profile generators for Visual Studio Developer
Command Prompt (VS2017+) and Visual Studio Developer PowerShell
(VS2019.2+)

Tested manually by deploying locally. My local environment has four
instances of VS installed, one VS2017 and multiple channels of VS2019.

We're wrapping the COM Visual Studio Setup Configuration API to query
for VS instances and retrieve the relevant properties.  Two different
namespaces are used so the end-user can turn off one or the other. For
instance, end user may prefer to always use Developer PowerShell. 

## Validation Steps Performed
1. Build locally using Visual Studio 2019
2. Deploy CascadiaPackage
3. Verify entries exist in profiles menu
4. Verify entries exist in settings.json
5. Open each profile
6. Validate start-in directory
7. Validate environment variables are as expected
8. Uninstall Windows Terminal - Dev package
9. Repeat.

Closes #3821
@ghost ghost added the Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. label Sep 15, 2021
@SheepReaper
Copy link

Well Ok then. Was not expecting M$ to just up and add native support like that. But hey 👍🏼 🥳

@ghost
Copy link

ghost commented Oct 20, 2021

🎉This issue was addressed in #7774, which has now been successfully released as Windows Terminal Preview v1.12.2922.0.:tada:

Handy links:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extensibility A feature that would ideally be fulfilled by us having an extension model. Area-Settings Issues related to settings and customizability, for console or terminal Issue-Task It's a feature request, but it doesn't really need a major design. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
None yet
Development

Successfully merging a pull request may close this issue.