11

In cmd.exe, I would simply run

%VS80COMNTOOLS%\vsvars32.bat

to set up the environment for running the Visual Studio command line tools (i.e. cl, link, mt, etc.). I wonder how I can set up the environment for running these tools in the Powershell. Sure, it is possible to run batch files using

start-process $env:vs80comntools\vsvars32.bat

but then the environment would be gone when the process terminates. I have already done some experiments with System.Diagnostics.StartProcessInfo, i.e.

$proc = start-process $env:vs80comntools\vsvars32.bat -passthru
$procInfo = proc.StartInfo

and then get the environment from $procInfo.EnvironmentVariables but this also does not work.

Are there any other ways to set up the environment in Powershell?

3 Answers3

5

The PowerShell Community Extensions has an Import-VisualStudioVars cmdlet.

heavyd
  • 65,321
2

PSCX's Import-VisualStudioVars is a large script that tries to duplicate what vsvars32.bat does. The problem there is that keeping them in sync requires effort and can be a source of bugs.

I prefer to rely on vsvars32.bat to do what it does, and import the env. vars. in to PowerShell. I do that with Invoke-CmdScript.ps1.

Jay Bazuzi
  • 4,210
0

Another option from PowerShell gallery: posh-vs Makes Visual Studio command line tools available in PowerShell. Supports Visual Studio 2017 and 2015.