10

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?

Uwe Honekamp
  • 865
  • 1
  • 12
  • 20

3 Answers3

5

The PowerShell Community Extensions has an Import-VisualStudioVars cmdlet.

heavyd
  • 62,847
  • 18
  • 155
  • 177
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,160
  • 6
  • 32
  • 41
  • Thanks for the reply. I have already considered that Import-VisualStudioVar more or less mocks the execution of vsvars32.bat instead of actually executing it. However, seeing that vsvars32.bat is quite stable for a specific version of VS I don't really think that there is a real problem of keeping the results of both options in sync. Nevertheless, I will give your proposal a try. – Uwe Honekamp Feb 06 '10 at 05:06
0

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