Wednesday 27 June 2007

vsvars32.bat in PowerShell = vsvars32.ps1

I've been using PS to do batch changes to my c# projects. Things like changing the build location to a common \bin folder and changing approriate HintPaths etc.

Anyway... Even though I've been using PS for a while I still use the old cmd line to do various tasks using msbuild, gacutil etc. It's always been a little annoying not having a ps1 version of vsvars32.bat. I've finally gotten around to doing it. It's a very literal translation but it works fine.


$env:VSINSTALLDIR="C:\Program Files\Microsoft Visual Studio 8\Common7\IDE"
$env:VCINSTALLDIR="C:\Program Files\Microsoft Visual Studio 8"
$env:FrameworkDir="c:\WINDOWS\Microsoft.NET\Framework"
$env:FrameworkVersion="v2.0.50727"
$env:FrameworkSDKDir="C:\Program Files\Microsoft Visual Studio 8\SDK\v2.0"
# Root of Visual Studio common files.

if("$env:VSINSTALLDIR" -eq ""){
echo "VSINSTALLDIR variable is not set."
exit
}
if("$env:VCINSTALLDIR" -eq ""){
$env:VCINSTALLDIR=$env:VSINSTALLDIR
}

# Root of Visual Studio ide installed files.
$env:DevEnvDir=$env:VSINSTALLDIR

# Root of Visual C++ installed files.
$env:MSVCDir="$env:VCINSTALLDIR\VC"

echo "Setting environment for using Microsoft Visual Studio 8 tools."
echo "(If you have another version of Visual Studio or Visual C++ installed and wish"
echo "to use its tools from the command line, run vcvars32.bat for that version.)"

#@REM VCINSTALLDIR\Common7\Tools dir is added only for real setup.

$env:PATH="$env:DevEnvDir;$env:MSVCDir\BIN;$env:VCINSTALLDIR\Common7\Tools;$env:VCINSTALLDIR\Common7\Tools\bin\prerelease;$env:VCINSTALLDIR\Common7\Tools\bin;$env:FrameworkSDKDir\bin;$env:FrameworkDir\$env:FrameworkVersion;$env:PATH;"
$env:INCLUDE="$env:MSVCDir\ATLMFC\INCLUDE;$env:MSVCDir\INCLUDE;$env:MSVCDir\PlatformSDK\include\prerelease;$env:MSVCDir\PlatformSDK\include;$env:FrameworkSDKDir\include;$env:INCLUDE"
$env:xLIB="$env:MSVCDir\ATLMFC\LIB;$env:MSVCDir\LIB;$env:MSVCDir\PlatformSDK\lib\prerelease;$env:MSVCDir\PlatformSDK\lib;$env:FrameworkSDKDir\lib;$env:LIB"