How to easily find the path to the Azure SDK csrun.exe?

I have some problems with Azure Compute Emulator that are not restarting properly. To solve this problem, I want to add the csrun /devfabric:stop call to the pre-build phase in the Visual Studio solution.

The problem is that csrun.exe is located in C:\Program Files\Windows Azure SDK\v1.4\bin on my machine, and this path is not in the %PATH% directory list. I do not want to rigidly indicate this path in my decision.

Is there a way to infer a path, like using some kind of environment variable or something similar?

+7
source share
2 answers

You can read the Azure SDK path from the registry by version. The last part of the path is the version ... Your code can be installed in the version or you can iterate over the v keys that are on the last. I would recommend having a constant for the supported version and, as you take the new SDK as a preliminary request.

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

There is a "InstallPath" key in these paths.

+6
source

I had the same problem and I created a PowerShell script that sets an environment variable with the path to the SDK bin folder. It will automatically search the registry and find the latest installed version. It also has a reserve of alternative registry location, depending on whether your script is running in 32-bit or 64-bit mode. Hope this helps!

Disclaimer: I removed some things from the script before posting it here, and I did not test it later, but I think it is not difficult to debug / configure it according to your needs.

 #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" (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::$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") + '"' } 
0
source

All Articles