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 us 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:

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:

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 prefered directory I have. The rest in the middle is the simple command which calls VsDevCmd.bat and then starts PowerShell.

ConEmu-Powershell-VsDevCmd

Now that we're done, click this out ;)

, , ,
  • Maximus

    Yep, that is working. But this method left cmd.exe in your working process tree.

    Another way – run vcvarsall.bat from you shell (PowerShell or Far Manager) and export changed environment from cmd to the parent process. The advantage – you can set up different settings at run time.

    Description: https://code.google.com/p/conemu-maximus5/wiki/ConEmuEnvironment#Export_variables

    And example command (I’m using that from Far Manager):
    “C:Program Files (x86)Microsoft Visual Studio 12.0VCvcvarsall.bat” x86 & “%ConEmuBaseDir%ConEmuC.exe” /export=CON

  • hyrmn

    I haven’t looked to see if my current method works with ConEmu, but I use my Powershell profile.ps1 to load VsVars. Here’s the relevant part:

    function Get-Batchfile ($file) {
    $cmd = “`”$file`” & set”
    cmd /c $cmd | Foreach-Object {
    $p, $v = $_.split(‘=’)
    Set-Item -path env:$p -value $v
    }
    }

    function Load-Vs2012Tools() {
    $batchFile = [System.IO.Path]::Combine($env:VS110COMNTOOLS, “VsDevCmd.bat”)
    Get-Batchfile -file $batchFile
    Write-Host -ForegroundColor ‘Yellow’ “VsVars has been loaded from: $batchFile”
    }

    Load-Vs2012Tools