次の方法で共有


Not really the last vsvars32 you will ever need...but close

I took Peter avise and for a while I've been using Chris's vsvars32, however it had some drawbacks,

1. It did not work from a 64bit PowerShell

2. For some reason Get-Batchfile did not work for me, I had to modify to call "echo" explicitly.

I also added a helper VsInstallDir and a alias for devenv.

 Enjoy,

 Oscar

function global:VsInstallDir($version="10.0")

{

$VSKey = $null

  if (test-path HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\$version)

  {

    $VSKey = get-itemproperty HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\$version

  }

  else

  {

    if (test-path HKLM:SOFTWARE\Microsoft\VisualStudio\$version)

    {

        $VSKey = get-itemproperty HKLM:SOFTWARE\Microsoft\VisualStudio\$version

    }

  }

  if ($VSKey -eq $null)

  {

      throw "Visual Studio not installed"

  }

  [System.IO.Path]::GetDirectoryName($VsKey.InstallDir)

}

function Get-Batchfile ($file) {

    $cmd = "echo off & `"$file`" & set"

    cmd /c $cmd | Foreach-Object {

        $p, $v = $_.split('=')

        Set-Item -path env:$p -value $v

    }

}

function global:VsVars32($version="10.0")

{

  $VsInstallPath = VsInstallDir($version)

  $VsToolsDir = [System.IO.Path]::GetDirectoryName($VsInstallPath)

  $VsToolsDir = [System.IO.Path]::Combine($VsToolsDir, "Tools")

  $BatchFile = [System.IO.Path]::Combine($VsToolsDir, "vsvars32.bat")

  Get-Batchfile $BatchFile

  [System.Console]::Title = "Visual Studio shell"

}

set-alias devenv ((VsInstallDir)+"\devenv.exe") -scope global