【发布时间】:2018-11-29 12:38:02
【问题描述】:
我将一个 UWP 应用更新为较新的 SDK,并将目标版本设置为 16299,将最低版本设置为 15063。
然后我使用 Windows.Foundation.UniversalApiContract 命名空间来使用新 SDK 的功能(如果可用)。示例:
xmlns:contract5NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"
<contract5Present:NavigationView x:Name="NavView" ...
构建失败,没有显示错误消息。但是当我将构建日志设置为详细时,它似乎找不到程序集:
Could not resolve this reference. Could not locate the assembly "Windows.Foundation.FoundationContract, Version=255.255.255.255, Culture=neutral, PublicKeyToken=null". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.
文件夹和文件存在于 C:\Program Files (x86)\Windows Kits\10\References**10.0.16299.0**\Windows.Foundation.FoundationContract\3.0.0.0 和 C:\Program Files (x86)\Windows Kits\10\References**10.0.15063.0**\Windows.Foundation.FoundationContract\3.0.0.0
更新 1: 看来这与我的资源字典和丙烯酸刷子有关。如果我将资源字典复制到空白应用程序,则会发生相同的错误。如果我从资源字典中删除合同内容和所有丙烯酸刷子,则构建成功。那么我在这里错过了什么?
更新 2: 我终于找到了问题所在(也许你可以重现,只需从一个空白应用程序开始(目标:Fall Creators,最低版本:Creators Update),创建一个 ResourceDictionary 并将其复制到其中):
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App6"
xmlns:contract5NotPresent="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractNotPresent(Windows.Foundation.UniversalApiContract,5)"
xmlns:contract5Present="http://schemas.microsoft.com/winfx/2006/xaml/presentation?IsApiContractPresent(Windows.Foundation.UniversalApiContract,5)"
>
<Thickness x:Key="HeaderMargin">20,41,0,0</Thickness>
<ResourceDictionary.ThemeDictionaries>
<ResourceDictionary x:Key="Light">
<Color x:Key="BrandColor">#D1D1D1</Color>
<contract5Present:AcrylicBrush x:Key="OptionsPaneBackground" BackgroundSource="Backdrop" TintColor="{StaticResource BrandColor}" TintOpacity="0.2" FallbackColor="#D1D1D1" />
</ResourceDictionary>
<ResourceDictionary x:Key="Dark">
<Color x:Key="BrandColor">#3F3F46</Color>
<contract5Present:AcrylicBrush x:Key="OptionsPaneBackground" BackgroundSource="Backdrop" TintColor="{StaticResource BrandColor}" TintOpacity="0.6" FallbackColor="#3F3F46" />
</ResourceDictionary>
</ResourceDictionary.ThemeDictionaries>
</ResourceDictionary>
如果我从字典中删除第一行(厚度),则构建成功。我的系统在 2018 年 4 月更新上运行,但我在另一台安装了 Fall Creators Update 的机器上遇到了同样的问题。
解决方案:我已将 ThemeResources 和 Styles 拆分为两个单独的 ResourceDictionaries,现在在我的主项目中构建成功。但我不明白为什么会发生这种情况以及为什么没有出现确切的错误消息。我花了大约 8 个小时(我的项目有超过 70000 行代码)来发现问题,对此我有点生气:)
【问题讨论】: