2011-10-04 10 views
7

Ho alcuni problemi con Azure Compute Emulator che non si riavvia correttamente. Per risolvere questo voglio aggiungere la chiamata csrun /devfabric:stop a un passo di pre-build nella soluzione di Visual Studio.Come si deduce opportunamente il percorso di Azure SDK csrun.exe?

Il problema è csrun.exe si trova in C:\Program Files\Windows Azure SDK\v1.4\bin sulla mia macchina e tale percorso non è nell'elenco delle directory %PATH%. Non voglio hardcode quel percorso nella mia soluzione.

C'è un modo per dedurre il percorso come l'utilizzo di alcune variabili d'ambiente o qualcosa di simile?

+0

Purtroppo, non ho trovato un modo ... –

risposta

6

È possibile leggere il percorso di Azure SDK dal registro per versione. L'ultima parte del percorso è la versione ... Il tuo codice può essere impostato su una versione oppure puoi scorrere le chiavi v trovando l'ultima. Ti consiglio di avere una costante per la versione che supporti e mentre prendi un nuovo SDK come pre-req.

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

C'è una chiave sotto quei sentieri "InstallPath" \.

0

Ho avuto lo stesso problema e ho prodotto uno script PowerShell che imposta una variabile di ambiente con il percorso della cartella bin SDK. Cerca automaticamente il registro e trova la versione installata più recente. Ha anche un fallback per la posizione del registro alternativo, a seconda se lo script viene eseguito in modalità 32 bit o 64 bit. Spero che sia d'aiuto!

Disclaimer: Ho rimosso alcuni elementi dallo script prima di postarlo qui e non l'ho testato in seguito, ma penso che non sia difficile eseguire il debug/adattarlo alle proprie esigenze.

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