如何方便地推断Azure SDK csrun.exe的路径?

发布于 2024-12-08 04:56:20 字数 307 浏览 2 评论 0原文

我遇到了一些 Azure 计算模拟器无法正确重新启动的问题。为了解决这个问题,我想在 Visual Studio 解决方案中的预构建步骤中添加 csrun /devfabric:stop 调用。

问题是 csrun.exe 位于我的计算机上的 C:\Program Files\Windows Azure SDK\v1.4\bin 中,并且该路径不在 %PATH% 上> 目录列表。我不想在我的解决方案中硬编码该路径。

有没有某种方法可以推断出路径,例如使用某些环境变量或类似的东西?

I have some problems with Azure Compute Emulator not restarting properly. To resolve this I want to add csrun /devfabric:stop call to a pre-build step in Visual Studio solution.

The problem is csrun.exe is located in C:\Program Files\Windows Azure SDK\v1.4\bin on my machine and that path is not on the %PATH% directories list. I don't want to hardcode that path in my solution.

Is there some way to deduce the path like using some environment variable or something similar?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

傲鸠 2024-12-15 04:56:20

您可以按版本从注册表中读取 Azure SDK 路径。路径的最后一部分是版本...您的代码可以设置为版本,也可以迭代 v 键查找最新版本。我建议您为您支持的版本设置一个常量,并且当您将新的 SDK 作为先决条件时。

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

这些路径下有一个“InstallPath”键。

You can read the Azure SDK path from the registry by version. The last part of the path is the version ... Your code can either be set to a version or you can iterate over the v keys finding the latest. I would recommend having a constant for the version you support and as you take a new SDK as a pre-req.

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

There's an "InstallPath" key under those paths.

还如梦归 2024-12-15 04:56:20

我遇到了同样的问题,我生成了一个 PowerShell 脚本,该脚本使用 SDK bin 文件夹的路径设置环境变量。它会自动搜索注册表并找到最新安装的版本。它还可以回退到备用注册表位置,具体取决于您的脚本是在 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") + '"'
}

I had this same problem and I produced 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 fallback to the alternate registry location, depending whether your script runs in 32bit or 64bit mode. Hope it helps!

Disclaimer: I removed some stuff from the script before posting it here and I didn't test it afterwards but I think it's not difficult to debug/adjust it 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" (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") + '"'
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文