Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / PowerShell

Using Visual Studio Developer Command Prompt With PowerShell

5.00/5 (3 votes)
29 Oct 2014CPOL2 min read 21.2K  
How to use Visual Studio developer command prompt with Powershell

Running Developer Command Prompt for Visual Studio

The Visual Studio developer command VsDevCmd.bat only works with the cmd.exe command line shell/processor, which is still the native command prompt in Windows. Try writing some command in Start->Run or Explorer’s address bar, and you’ll find that you need to use the cmd/batch command syntax (for example, using %SOME_NAME% syntax for variables).

What if you want to use VsDevCmd.bat? You want the stuff it adds temporarily to the PATH and all the other goodies it brings, but prefer to work in Powershell?

Using VsDevCmd With PowerShell

You can try to run VsDevCmd.bat from PowerShell, but this will execute another command prompt shell on top of it.

However, you can also easily do the opposite. Run the VsDevCmd.bat, and from the command prompt, just type PowerShell and press ENTER. The new Powershell session will inherit all the fluff that VsDevCmd.bat added to the command prompt session.

A Quick Shortcut

You can always have a simple shortcut to load VsDevCmd.bat with Powershell instead of writing everytime.

Simply create a new text file, and enter the following in it:

cmd.exe /k ""%VS120COMNTOOLS%VsDevCmd.bat" & powershell"

Save the file and change its extension to .bat. When you run it, it will run the command prompt and keep it open, run VsDevCmd.bat, and then powershell.

You can test it by running, ensuring the prompt shows the PS > prompt for PowerShell, then run msbuild to ensure it was added to the PATH by DevCmd.bat.

Using By Default, ConEmu

On my personal machine, I use ConEmu as my all-time console environment. If you don’t know about it, Scott Hanselman described it in depth.

Among many other things, ConEmu allows you to create tasks that can be executed by default when you open a new console tab. This allows you to have for example some preset (task) for sat Bash/cygwin, another for cmd.exe, another for PowerShell, etc. Maybe even another task that loads some extra variables or whatever that you don’t want always attached, but still want them handy when you use the console. It also allows you to optionally choose one task to be the default when you open ConEmu.

So, for me, the task I set to be the default in ConEmu is the following:

* > cmd.exe /k ""%VS120COMNTOOLS%VsDevCmd.bat" & powershell" -new_console:d:D:\Some_Folder

the first * > bits are ConEmu specific, telling it to run task as admin and make it active tab (if you can set multiple tabs in the same task). And the -new_console: switch allows passing other parameters to ConEmu when starting, like d:D:\_data, which sets the start-up directory to a preferred directory I have. The rest in the middle is the simple command which calls VsDevCmd.bat and then starts PowerShell.

ConEmu-Powershell-VsDevCmd

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)