If you are like me, you use the Visual Studio Command Prompt frequently, because you need the environment that gets set up by the vcvarsall batch. I’m using the PowerShell now exclusively, but still need this environment. Just calling the batch file doesn’t get the variables set in PowerShell. Adam Barr has a good explanation and solution here (and the interesting bit below is taken from his blog and credited there to Bruce Payette).
My goal was to have these environment variables set for every instance of PowerShell. Not rocket-science, but not terribly straight forward to a newbie PowerShell user either. To do that, I needed to add a script that will get run on every invocation of PowerShell. Here is what I did.
If you don’t yet have a profile set up, then create the required directory (explanation of profile naming is here):
mkdir "$home/My Documents/WindowsPowerShell"
Open your profile (or create if it doesn’t exist):
notepad "$home/My Documents/WindowsPowerShell/Microsoft.PowerShell_profile.ps1"
Paste the following into your profile:
pushd 'C:\\Program Files\\Microsoft Visual Studio 8\\vc' cmd /c “vcvarsall.bat&set” | foreach { if ($_ -match “=”) { $v = $_.split(“=”); set-item -force -path "ENV:\\$($v[0])" -value "$($v[1])" } } popd
And then start a new PowerShell. Now the environment should be set properly.
Update: I fixed the path to the default profile. Thanks to dreamlusion for pointing out that my info was pre-release and out of date.