Saturday, November 03, 2012

Updating the last vsvars32.ps1 you'll ever need for x64

I've been using Chris Tavares' ultimate vsvars32.ps1 in my powershell start-up script pretty much since it was first posted. But of course, it shows its age in that it assumes you're running 32-bit, given the registry path it uses.

Now, you can hard-code based on your hardware, or assume that anything you're using nowadays is 64-bit (except, of course, when you explicitly run the x86 version of powershell); and there are various ways of detecting current bit-ness. But the simplest way of doing things is to take the behaviour-driven style of detection used as standard in JavaScript and just write

or reversing the order of the two registry keys to taste.

There are of course alternative ways of getting the path we're eventually aiming at e.g. via environment variable like VS###COMNTOOLS where the ### is a number like 90, 100 or, nowadays, 110, depending on VS version.

Post a Comment