何らかの理由で、開発マシンでWindows 8を試してみることにしました。これまでのところ、非常に良いことですが、Powershellを起動しようとするまで、いくつかのカスタマイズがあり、PATH
変更をから引き出すなどvcvars32.bat
、さまざまな開発ツールすべてにアクセスできます。
最初に、スクリプトはここからhttps://stackoverflow.com/questions/138144/whats-in-your-powershell-profile-ps1fileからプルされ、x64 Powershellインスタンス内で実行できるようにいくつかの変更が加えられました。このような:
function Get-Batchfile($file)
{
$theCmd = "`"$file`" & set"
cmd /c $theCmd | Foreach-Object {
$thePath, $theValue = $_.split('=')
Set-Item -path env:$thePath -value $theValue
}
}
function VsVars32($version = "10.0")
{
$theKey = "HKLM:SOFTWARE\Wow6432Node\Microsoft\VisualStudio\" + $version
$theVsKey = get-ItemProperty $theKey
$theVsInstallPath = [System.IO.Path]::GetDirectoryName($theVsKey.InstallDir)
$theVsToolsDir = [System.IO.Path]::GetDirectoryName($theVsInstallPath)
$theVsToolsDir = [System.IO.Path]::Combine($theVsToolsDir, "Tools")
$theBatchFile = [System.IO.Path]::Combine($theVsToolsDir, "vsvars32.bat")
write-host $theBatchFile
Get-Batchfile $theBatchFile
[System.Console]::Title = "Visual Studio " + $version + " Windows Powershell"
}
VsVars32
そして、それはWindows 7で完璧に機能しました。今、Windows 8で、私は以下を取り戻します:
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
さらに調査すると、cmd /c
動作の仕方で何かが変わったように見えます。cmd
回線を単独で実行すると、次のようになります。
PS> cmd /c "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
'C:\Program' is not recognized as an internal or external command, operable program or batch file.
誰かが同様の問題に遭遇しましたが、うまくいけば回避策がありますか?
編集:
以下の回答で述べたように、引用の問題がある可能性があります。私は投稿する前でさえこれを試みました、そして私のトラブルのためにこれを得ました:
PS> cmd /c ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat""
x86 : The term 'x86' is not recognized as the name of a cmdlet, function, script file, or operable program. Check the
spelling of the name, or if a path was included, verify that the path is correct and try again.
At line:1 char:28
+ cmd /c ""C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvar ...
+ ~~~
+ CategoryInfo : ObjectNotFound: (x86:String) [], CommandNotFoundException
+ FullyQualifiedErrorId : CommandNotFoundException
引用のいくつかの異なる順列:
単一引用符で二重にラップ:
PS> echo '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"'
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
PS> cmd /c '"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"'
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
エスケープされた二重引用符:
PS> echo "`"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat`""
"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat"
PS> cmd /c "`"C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\Tools\vsvars32.bat`""
'C:\Program' is not recognized as an internal or external command,
operable program or batch file.
もう一度:Windows 7でもまったく同じスクリプトが機能しました。