Comment déduire commodément le chemin d’access à Azure SDK csrun.exe?

J’ai quelques problèmes avec Azure Compute Emulator qui ne redémarre pas correctement. Pour résoudre ce problème, je veux append csrun /devfabric:stop appel à une étape de pré-construction dans la solution Visual Studio.

Le problème est que csrun.exe se trouve dans C:\Program Files\Windows Azure SDK\v1.4\bin sur mon C:\Program Files\Windows Azure SDK\v1.4\bin et que ce chemin ne figure pas dans la liste des répertoires %PATH% . Je ne veux pas coder en dur ce chemin dans ma solution.

Y a-t-il un moyen de déduire le chemin comme l’utilisation d’une variable d’environnement ou de quelque chose de similaire?

Vous pouvez lire le chemin Azure SDK à partir du registre par version. La dernière partie du chemin est la version … Votre code peut être défini sur une version ou vous pouvez parcourir les clés v pour trouver la dernière. Je vous recommande d’avoir une constante pour la version que vous supportez et que vous prenez un nouveau SDK comme pré-requête.

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

Il y a une clé “InstallPath” sous ces chemins.

J’ai eu le même problème et j’ai produit un script PowerShell qui définit une variable d’environnement avec le chemin d’access au dossier bin SDK. Il va automatiquement rechercher dans le registre et trouver la dernière version installée. Il a également une solution de remplacement à l’emplacement de registre alternatif, selon que votre script s’exécute en mode 32 bits ou 64 bits. J’espère que cela aide!

Disclaimer: J’ai enlevé certaines choses du script avant de le poster ici et je ne l’ai pas testé après mais je pense qu’il n’est pas difficile de le déboguer / de l’ajuster à vos besoins.

 #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 resortingeve the largest version number #3. from the largest version number key resortingeve the "InstallPath" ssortingng 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 $azureeSDKPathVariable = 'AzureSDKBin' $azureeRegistryKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting' $azureeAlternateRegistryKey = 'HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\Microsoft SDKs\ServiceHosting' #this is in case the PowerShell runs in 32bit mode on a 64bit machine $azureeMatchedKey = '' #check if the environment variable was already defined if ([environment]::GetEnvironmentVariable($azureeSDKPathVariable,"User").Length -eq 0) { 'Variable ' + $azureeSDKPathVariable + ' is not defined, proceeding...' #try reading the registry key $keyExists = Get-Item -Path Registry::$azureeRegistryKey -ErrorAction SilentlyContinue $azureeMatchedKey = $azureeRegistryKey #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: ' + $azureeRegistryKey + ', attempting search in alternate location: ' + $azureeAlternateRegistryKey #search the alternate location $keyExists = Get-Item -Path Registry::$azureeAlternateRegistryKey -ErrorAction SilentlyContinue $azureeMatchedKey = $azureeAlternateRegistryKey #make a note that we found this registry key if ($keyExists.Length -eq 0) { 'Could not find registry key for determining Azure SDK installation: ' + $azureeAlternateRegistryKey 'Script failed...' exit 1 } } 'Found Azure SDK registry key: ' + $azureeMatchedKey #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" (eg "v2.2", "v2.3") #3. sort the results by the "PSChildName" property from which we removed the starting "v" (ie 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::$azureeMatchedKey | 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($azureeSDKPathVariable, $installPath + 'bin\', "User") 'Assigned the value "' + [environment]::GetEnvironmentVariable($azureeSDKPathVariable,"User") + '" to environment variable "' + $azureeSDKPathVariable + '"' } else { 'Environment variable "' + $azureeSDKPathVariable + '" is already defined and has a value of "' + [environment]::GetEnvironmentVariable($azureeSDKPathVariable,"User") + '"' }