WAT080 是否有解决方法:无法找到 Microsoft Azure SDK

Is there a workaround for WAT080 : Failed to locate the Microsoft Azure SDK

我正在构建一个需要安装 Azure SDK 的项目。不幸的是,我无法安装 SDK,因为 VSTools 安装程序没有 运行 在 Docker 容器中。我正在尝试 重新创建 安装程序执行的步骤,以便项目认为 SDK 已正确安装。我收到的错误消息是:

C:\Program Files (x86)\Microsoft Visual Studio17\BuildTools\MSBuild\Microsoft\VisualStudio\v15.0\Windows Azure Tools.9\Microsoft.WindowsAzure.targets(1093,5): error : WAT080 : Failed to locate the Microsoft Azure SDK. Please make sure t he Microsoft Azure SDK v2.9 is installed. [C:\BuildAgent\work\da35ef67e7dea9a9\EMCloudService\EMCloudService.ccproj]

.targets 文件中的第 1093 行是:

  <Target
      Name="VerifySDKInstallation"> // <---- Line 1093

    <WATMessage Condition=" !Exists('$(ServiceHostingSDKInstallDir)') or
                            !Exists('$(ServiceHostingSDKBinDir)') or
                            !Exists('$(ServiceHostingSDKTaskPath)') "
                Type="Error"
                Code="WAT080"
                Arguments="$(ActiveAzureSdkVersion)" />

    <WATMessage Condition=" !Exists('$(AzureClientLibInstallDir)') or
                            !Exists('$(AzureClientLibToolsRefDir)') or
                            !Exists('$(StorageClientAssemblyFullPath)') "
                Type="Error"
                Code="WAT081"
                Arguments="$(ActiveAzureClientLibVersion)" />

  </Target>

所以,错误似乎是因为这三个路径之一不存在。第一个来自以下行:

<ServiceHostingSDKInstallDir Condition=" '$(ServiceHostingSDKInstallDir)' == '' ">$([MSBuild]::GetRegistryValueFromView('$(ServiceHostingSDKRegistryKey)', 'InstallPath', null, RegistryView.Registry32))</ServiceHostingSDKInstallDir>

所以,基本上是在注册表中查找。我从一台工作机器上复制了这个值,它的值为 "C:\Program Files\Microsoft SDKs\Azure.NET SDK\"

我把那个目录复制过来了。接下来是ServiceHostingSDKBinDir,定义为:

<ServiceHostingSDKBinDir     Condition=" '$(ServiceHostingSDKBinDir)' == '' ">$(ServiceHostingSDKInstallDir)bin\</ServiceHostingSDKBinDir>

这应该没问题,因为 ServiceHostingSDKInstallDir 存在。最后是 ServiceHostingSDKTaskPath,即:

<ServiceHostingSDKTaskPath   Condition=" '$(ServiceHostingSDKTaskPath)' == '' ">$(ServiceHostingSDKBinDir)Microsoft.ServiceHosting.Tools.MSBuildTasks.dll</ServiceHostingSDKTaskPath>

所以,看起来我真的应该能够复制 "C:\Program Files\Microsoft SDKs\Azure.NET SDK\" 目录,为 ActiveAzureSdkVersion 和 ServiceHostingSDKInstallDir 传递正确的参数,一切都应该正常工作:

msbuild EM.sln `
  /p:ActiveAzureSdkVersion="2.9" `
  /p:ServiceHostingSDKInstallDir="C:/Program Files/Microsoft SDKs/Azure/.NET SDK/"

但是,我仍然遇到同样的错误。谁能想到我需要复制或传递的其他内容?谢谢!

Is there a workaround for WAT080 : Failed to locate the Microsoft Azure SDK

根据文件Microsoft.WindowsAzure.targets(1093,5),我们可以得到如下代码片段:

  <PropertyGroup>
    <ActiveAzureSdkVersion Condition=" '$(ActiveAzureSdkVersion)' == '' ">$([MSBuild]::GetRegistryValueFromView('HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows Azure Tools for Microsoft Visual Studio.0\v2.9', 'ActiveWindowsAzureVersion', null, RegistryView.Registry32))</ActiveAzureSdkVersion>
    <!-- Sdk reversion -->
    <ActiveAzureSdkVersion Condition=" '$(ActiveAzureSdkVersion)' == '' ">2.9</ActiveAzureSdkVersion>
    <ServiceHostingSDKRegistryKey>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v$(ActiveAzureSdkVersion)</ServiceHostingSDKRegistryKey>
    <ServiceHostingSDKInstallDir Condition=" '$(ServiceHostingSDKInstallDir)' == '' ">$([MSBuild]::GetRegistryValueFromView('$(ServiceHostingSDKRegistryKey)', 'InstallPath', null, RegistryView.Registry32))</ServiceHostingSDKInstallDir>

    <!-- Ensure ServiceHostingSDKInstallDir has a trailing slash, so it can be concatenated -->
    <ServiceHostingSDKInstallDir Condition=" '$(ServiceHostingSDKInstallDir)' != '' and !HasTrailingSlash('$(ServiceHostingSDKInstallDir)')">$(ServiceHostingSDKInstallDir)\</ServiceHostingSDKInstallDir>

    ...
    ...
  </PropertyGroup>

我们可以知道参数ServiceHostingSDKRegistryKey的值是:

HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Microsoft SDKs\ServiceHosting\v$(ActiveAzureSdkVersion)

简单的知道$(ActiveAzureSdkVersion)的值是2.9,所以ServiceHostingSDKInstallDir的值应该是[=的值参数 ServiceHostingSDKRegistryKey.

的 16=]

然后,我们打开regedit,将路径切换到上面的注册表项:

InstallPath 的值是 C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9\ 而不是旧值 C:\Program Files\Microsoft SDKs\Azure.NET SDK\

此外,您可以发现该 Azure SDK 的位置也是 C:\Program Files\Microsoft SDKs\Azure\.NET SDK\v2.9,您在命令行中使用参数 /p:ServiceHostingSDKInstallDir.

指定了它

因此,出现此问题的原因是注册表项的值不正确。虽然你用 /p:ServiceHostingSDKInstallDir 重写它,当将 Microsoft.WindowsAzure.targets 导入项目文件并执行目标 VerifySDKInstallation 时,似乎 MSBuild/Visual Studio 将调用参数 $(ServiceHostingSDKInstallDir ) 根据就近原则在 .targets 文件中。

此问题的解决方法,您可以尝试将注册表项更改为正确的路径或者如果您不想修改注册表,可以尝试将SDK文件夹复制到旧路径C:\Program Files\Microsoft SDKs\Azure.NET SDK\.

希望对您有所帮助。

想通了这一点。 真正 帮助的是将以下内容添加到 .targets 文件中,就在第 1093 行下方:

<Message Text="ServiceHostingSDKInstallDir = $(ServiceHostingSDKInstallDir)" />
<Message Text="ServiceHostingSDKBinDir = $(ServiceHostingSDKBinDir)" />
<Message Text="ServiceHostingSDKTaskPath = $(ServiceHostingSDKTaskPath)" />

这让我看到了它试图寻找的路径。在构建输出中,我得到:

ServiceHostingSDKInstallDir = C:/Program Files/Microsoft SDKs/Azure/.NET SDK/
ServiceHostingSDKBinDir = C:/Program Files/Microsoft SDKs/Azure/.NET SDK/bin\
ServiceHostingSDKTaskPath = C:/Program Files/Microsoft SDKs/Azure/.NET SDK/bin\Microsoft.ServiceHosting.Tools.MSBuildTasks.dll

因此,路径 C:/Program Files/Microsoft SDKs/Azure/.NET SDK/bin\ 不存在,因为它缺少版本号。原来ActiveAzureSdkVersion这个参数只有在通过注册表获取路径的时候才会用到,所以传进去对我来说是没有意义的。相反,我需要传入 SDK 的完整路径,包括版本:

MSBuild.exe .\EM.sln /p:ServiceHostingSDKInstallDir="C:/Program Files/Microsoft SDKs/Azure/.NET SDK/v2.9/"

希望这对某人有所帮助!