7

Azure Compute Emulator가 제대로 재시작되지 않는 문제가 있습니다. 이 문제를 해결하려면 csrun /devfabric:stop 호출을 Visual Studio 솔루션의 미리 빌드 단계에 추가하고 싶습니다.Azure SDK csrun.exe에 대한 경로를 어떻게 쉽게 추론합니까?

문제는 csrun.exe가 내 컴퓨터의 C:\Program Files\Windows Azure SDK\v1.4\bin에 있으며 그 경로가 %PATH% 디렉토리 목록에 없음을 나타냅니다. 내 솔루션에서 그 경로를 하드 코딩하고 싶지 않습니다.

일부 환경 변수 또는 이와 유사한 것을 사용하는 것과 같은 경로를 추론 할 수있는 방법이 있습니까?

+0

유감스럽게도 그런 식으로는 찾지 못했습니다 ... –

답변

6

Azure SDK 경로는 버전별로 레지스트리에서 읽을 수 있습니다. 경로의 마지막 부분은 버전입니다 ... 코드를 버전으로 설정하거나 v 키를 반복하여 최신 버전을 찾을 수 있습니다. 나는 당신이 지원하는 버전에 대한 상수를 가져야하고 새로운 SDK를 pre-req로 가져갈 것을 권한다. 마이크로 소프트 \ 마이크로 소프트의 SDK \ ServiceHosting \ V1.4에

에 "INSTALLPATH"그 경로 아래에 키가있다 \

HKEY_LOCAL_MACHINE \ 소프트웨어.

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") + '"' 
}