【问题标题】:Referencing Windows SDK winmd files and VS Team Services build引用 Windows SDK winmd 文件和 VS Team Services 构建
【发布时间】:2018-06-13 02:20:51
【问题描述】:

我创建了一个 C# .Net 标准库,它引用了两个 Windows SDK 库。

参考文献是

  • C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd
  • C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd

这适用于我的本地开发机器。

VS Team Services 构建首先显示以下警告:

2018-06-13T01:17:22.3393846Z ##[warning]C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\MSBuild\15.0\Bin\Microsoft.Common.CurrentVersion.targets(2106,5): Warning MSB3245: Could not resolve this reference. Could not locate the assembly "Windows.Foundation.FoundationContract". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.

后来它失败并出现以下错误:

Error CS0246: The type or namespace name 'Windows' could not be found (are you missing a using directive or an assembly reference?)

天真地,我以为我只需在 Visual Studio 中将 Copy Local to True 设置为 true,一切都会好起来的。我错了。

问题

如何在 VSTS 中构建引用 SDK winmd 文件的项目?

【问题讨论】:

  • 您使用的是托管代理还是私有代理?

标签: c# winapi azure-devops azure-pipelines winmd


【解决方案1】:

参考这些步骤来处理这个问题:

  1. 在 Visual Studio 中右键单击项目 > 编辑 {项目名称}
  2. 将这些程序集的相对路径替换为绝对路径

示例代码:

<ItemGroup>
    <Reference Include="Windows.Foundation.FoundationContract">
      <HintPath>C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
    </Reference>
    <Reference Include="Windows.Foundation.UniversalApiContract">
      <HintPath>C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
      <IsWinMDFile>true</IsWinMDFile>
    </Reference>
  </ItemGroup>

【讨论】:

  • 我重新组织了我的项目,因此只有主项目(即 UWP)使用这些 API,因此问题消失了,但我相信您的解决方案有效,我将其标记为答案。
  • 我在问题中看不到任何相对路径名。你能解释一下吗?
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-04-05
  • 1970-01-01
相关资源
最近更新 更多