6

The windows v7.1 SDK has a SetEnv.Cmd script in its binary folder to correctly setup its environment. The problem is this script obviously only works with cmd.exe and I can't find an equivalent for powershell anywhere.

So am I forced to use cmd.exe or is there a way to use powershell (apart from manually rewriting the SetEnv.Cmd script - if even that would work?).

Voo
  • 29,040
  • 11
  • 82
  • 156

2 Answers2

2

You can launch an instance of CMD.EXE, run SetEnv.cmd, and then launch PowerShell from within the CMD window. The PowerShell instance that opens up will import the environment variables from the CMD instance that spawned it.

It's ugly, but it works.

I wrote a batch script to do it for me, and just created a shortcut to it on my desktop. Here's an example:

@echo off
call "C:\Path\To\SetEnv.cmd" param1 param2 param3
powershell.exe -noexit
mikekol
  • 1,782
  • 12
  • 14
  • In this case "works as expected" is all I care for. Powershell is oh so much nicer than cmd. – Voo Aug 07 '13 at 23:52
2

Someone wrote a ps1 script that parses out the SDK's setenv so you can avoid the extra processes:

http://www.tavaresstudios.com/Blog/post/The-last-vsvars32ps1-Ill-ever-need.aspx

x0n
  • 51,312
  • 7
  • 89
  • 111
  • 1
    Accepted as the answer because it seems to work fine (although it sets some variables that I don't think should actually be set and needs a tweak to ignore null variables) and it's more elegant (or overengineered ;)) than the other solution. – Voo Aug 08 '13 at 17:10
  • And the link is dead – mlt Dec 06 '18 at 23:08
  • @mlt install-module pscx; Import-VisualStudioVars -VisualStudioVersion 2017 – x0n Dec 10 '18 at 03:28