7

Azure Compute Emulator が正しく再起動しないという問題があります。これを解決するにcsrun /devfabric:stopは、Visual Studio ソリューションでビルド前のステップへの呼び出しを追加します。

問題は、csrun.exe がC:\Program Files\Windows Azure SDK\v1.4\bin私のマシンにあり、そのパスが%PATH%ディレクトリ リストにないことです。ソリューションでそのパスをハードコーディングしたくありません。

環境変数などを使用するなど、パスを推測する方法はありますか?

4

2 に答える 2

6

バージョンごとにレジストリからAzureSDKパスを読み取ることができます。パスの最後の部分はバージョンです...コードをバージョンに設定するか、vキーを繰り返して最新のものを見つけることができます。サポートするバージョンの定数を用意し、前提条件として新しいSDKを使用することをお勧めします。

HKEY_LOCAL_MACHINE \ SOFTWARE \ Microsoft \ Microsoft SDKs \ ServiceHosting \ v1.4

これらのパスの下に「InstallPath」キーがあります。

于 2011-10-04T12:24:31.550 に答える
0

これと同じ問題があり、SDK bin フォルダーへのパスを使用して環境変数を設定する PowerShell スクリプトを作成しました。レジストリを自動的に検索し、インストールされている最新バージョンを見つけます。また、スクリプトが 32 ビット モードで実行されるか 64 ビット モードで実行されるかに応じて、別のレジストリの場所へのフォールバックもあります。それが役に立てば幸い!

免責事項:ここに投稿する前にスクリプトからいくつかのものを削除し、後でテストしませんでしたが、必要に応じてデバッグ/調整することは難しくないと思います.

#the script attempts to perform the following:
#1. look for the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting" registry key
#2. if the above key is present then read the child keys and retrieve the largest version number
#3. from the largest version number key retrieve the "InstallPath" string value to determine the path of the latest Azure SDK installation
#4. add an environment variable called "AzureSDKBin" (if not already added) with the path to the "bin" folder of the latest Azure SDK installation

#define the name of the config variable
$azureSDKPathVariable = 'AzureSDKBin'
$azureRegistryKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting'
$azureAlternateRegistryKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\ServiceHosting' #this is in case the PowerShell runs in 32bit mode on a 64bit machine
$azureMatchedKey = ''

#check if the environment variable was already defined
if ([environment]::GetEnvironmentVariable($azureSDKPathVariable,"User").Length -eq 0) {
    'Variable ' + $azureSDKPathVariable + ' is not defined, proceeding...'

    #try reading the registry key
    $keyExists = Get-Item -Path Registry::$azureRegistryKey -ErrorAction SilentlyContinue

    $azureMatchedKey = $azureRegistryKey #make a note that we found this registry key

    #stop if the key does not exist
    if ($keyExists.Length -eq 0) {
        'Could not find registry key in primary location: ' + $azureRegistryKey + ', attempting search in alternate location: ' + $azureAlternateRegistryKey

        #search the alternate location
        $keyExists = Get-Item -Path Registry::$azureAlternateRegistryKey -ErrorAction SilentlyContinue

        $azureMatchedKey = $azureAlternateRegistryKey #make a note that we found this registry key

        if ($keyExists.Length -eq 0) {
            'Could not find registry key for determining Azure SDK installation: ' + $azureAlternateRegistryKey
            'Script failed...'
            exit 1
        }
    }

    'Found Azure SDK registry key: ' + $azureMatchedKey

    #logic for determining the install path of the latest Azure installation
    #1. get all child keys of the matched key
    #2. filter only keys that start with "v" (e.g. "v2.2", "v2.3")
    #3. sort the results by the "PSChildName" property from which we removed the starting "v" (i.e. only the version number), descending so we get the latest on the first position
    #4. only keep the first object
    #5. read the value named "InstallPath" under this object
    $installPath = (Get-ChildItem -Path Registry::$azureMatchedKey | Where-Object { $_.PSChildName.StartsWith("v") } | sort @{expression={ $_.PSChildName.TrimStart("v") }} -descending | Select-Object -first 1| Get-ItemProperty -name InstallPath).InstallPath

    'Detected this Azure SDK installation path: "' + $installPath + '"'

    #set the variable with the "bin" folder
    [Environment]::SetEnvironmentVariable($azureSDKPathVariable, $installPath + 'bin\', "User")

    'Assigned the value "' + [environment]::GetEnvironmentVariable($azureSDKPathVariable,"User") + '" to environment variable "' + $azureSDKPathVariable + '"'
}
else {
    'Environment variable "' + $azureSDKPathVariable + '" is already defined and has a value of "' + [environment]::GetEnvironmentVariable($azureSDKPathVariable,"User") + '"'
}
于 2014-11-16T11:58:37.050 に答える