October 04, 2009

How to target compilers in PS?

If PS is targeting any other compiler than you need then simply change the compiler directory to make sure it compiles with correct version of .NET.

E.g.

cd 'C:\WINDOWS\Microsoft.NET\Framework\v3.5'
.\csc /t:library 'C:\Program Files\Microsoft SDKs\Windows\v6.0A\bin\generatedClient.cs' /r:"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\System.ServiceModel.dll"

Following script you can use to setup environment variables for VS2005

   1:  $env:VSINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 8"
   2:  $env:VCINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 8\VC"
   3:  $env:DevEnvDir="$env:VSINSTALLDIR\Common7\IDE"
   4:  $env:FrameworkSDKDir="$env:VSINSTALLDIR\SDK\v2.0"
   5:  $FrameworkPath=$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
   6:  $env:FrameworkDir=$(split-path $FrameworkPath -Parent)
   7:  $env:FrameworkVersion=$(split-path $FrameworkPath -Leaf)
   8:  $env:PATH="$env:VSINSTALLDIR\Common7\IDE;$env:VCINSTALLDIR\BIN;$env:VSINSTALLDIR\Common7\Tools;$env:VSINSTALLDIR\Common7\Tools\bin;$env:VCINSTALLDIR\PlatformSDK\bin;$env:FrameworkSDKDir\bin;$env:FrameworkDir\$env:FrameworkVersion;$env:VCINSTALLDIR\VCPackages;$env:PATH"
   9:  $env:INCLUDE="$env:VCINSTALLDIR\ATLMFC\INCLUDE;$env:VCINSTALLDIR\INCLUDE;$env:VCINSTALLDIR\PlatformSDK\include;$env:FrameworkSDKDir\include;$env:INCLUDE"
  10:  $env:LIB="$env:VCINSTALLDIR\ATLMFC\LIB;$env:VCINSTALLDIR\LIB;$env:VCINSTALLDIR\PlatformSDK\lib;$env:FrameworkSDKDir\lib;$env:LIB"
  11:  $env:LIBPATH="$FrameworkPath;$env:VCINSTALLDIR\ATLMFC\LIB
Following script you can use to setup environment variables for VS2008
   1:  $env:VSINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 9.0"
   2:  $env:VCINSTALLDIR="$env:ProgramFiles\Microsoft Visual Studio 9.0\VC"
   3:  $env:DevEnvDir="$env:VSINSTALLDIR\Common7\IDE"
   4:  $env:FrameworkSDKDir="$env:VSINSTALLDIR\SDK\v3.5"
   5:  $FrameworkPath=$([System.Runtime.InteropServices.RuntimeEnvironment]::GetRuntimeDirectory())
   6:  $env:FrameworkDir=$(split-path $FrameworkPath -Parent)
   7:  $env:FrameworkVersion=$(split-path $FrameworkPath -Leaf)
   8:  $env:PATH="$env:VSINSTALLDIR\Common7\IDE;$env:VCINSTALLDIR\BIN;$env:VSINSTALLDIR\Common7\Tools;$env:VSINSTALLDIR\Common7\Tools\bin;$env:VCINSTALLDIR\PlatformSDK\bin;$env:FrameworkSDKDir\bin;$env:FrameworkDir\$env:FrameworkVersion;$env:VCINSTALLDIR\VCPackages;$env:PATH"
   9:  $env:INCLUDE="$env:VCINSTALLDIR\ATLMFC\INCLUDE;$env:VCINSTALLDIR\INCLUDE;$env:VCINSTALLDIR\PlatformSDK\include;$env:FrameworkSDKDir\include;$env:INCLUDE"
  10:  $env:LIB="$env:VCINSTALLDIR\ATLMFC\LIB;$env:VCINSTALLDIR\LIB;$env:VCINSTALLDIR\PlatformSDK\lib;$env:FrameworkSDKDir\lib;$env:LIB"
  11:  $env:LIBPATH="$FrameworkPath;$env:VCINSTALLDIR\ATLMFC\LIB"