Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

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?

share|improve this question
add comment

2 Answers

up vote 4 down vote accepted

The PowerShell Community Extensions has an Import-VisualStudioVars cmdlet.

share|improve this answer
    
Thanks a lot. This is exactly what I'm looking for. –  Uwe Honekamp Feb 4 '10 at 20:20
add comment

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.

share|improve this answer
    
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 6 '10 at 5:06
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.