3

I am trying all kinds of variants of the following command:

powershell -command "'C:\Program Files (x86)\Microsoft Visual Studio 10.0\vc\vcvarsall.bat' x86" -noexit

I am hoping to run Powershell with the VS environment vars - to no avail. I just cannot get the quotes right.

3 Answers 3

5

Have a look at the PowerShell Community Extensions. It comes with a command to invoke a batch file, "remember" what env vars it set and bring those into your PowerShell session. In fact, my profile does just this with the VS vars e.g.:

Import-Module Pscx

function Import-VS9Vars
{
    $vcargs = ?: {$Pscx:Is64BitProcess} {'amd64'} {'x86'}
    Push-EnvironmentBlock -Description "Before importing VS 2008 $vcargs var"
    Invoke-BatchFile "${env:VS90COMNTOOLS}..\..\VC\vcvarsall.bat" $vcargs
}

function Import-VS10Vars
{
    $vcargs = ?: {$Pscx:Is64BitProcess} {'amd64'} {'x86'}
    Push-EnvironmentBlock -Description "Before importing VS 2010 $vcargs vars"
    Invoke-BatchFile "${env:VS100COMNTOOLS}..\..\VC\vcvarsall.bat" $vcargs
}

Import-VS10Vars

The important command is the Invoke-BatchFile. The source to this function comes in the download so if you don't want to use the whole module, you can copy out just that one function if you'd like.

Sign up to request clarification or add additional context in comments.

Comments

1

Check out Get-BatchFile from Bruce Payette's "Windows PowerShell in Action, Second Edition"

Link to Get-BatchFile

It’s also possible to use these batch files from PowerShell by executing them, dumping the changes that have been made to the environment, and then importing those changes back into the PowerShell environment.

4 Comments

The link refers to the book summary on the Internet. Do you suggest me buying the book in order to learn what this is all about?
Suppose I have found Get_BatchFile and added it to my profile. How do I run powershell passing it the script on the command line?
My apologies, that link takes me to the PDF where it provides the script and explains how it works. It runs the vcvarsall.bat and sets the variables correctly in PowerShell.
I have found what you mean in the appendix A.1.7 of the PDF referenced by the link. Thanks.
0

There is an example here.

And don't forget the icons :)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.