C# UWP 构建失败/Windows.Foundation.FoundationContract 丢失 [英] C# UWP Build failed / Windows.Foundation.FoundationContract missing

查看:24
本文介绍了C# UWP 构建失败/Windows.Foundation.FoundationContract 丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我将一个 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" ...

构建失败,没有显示错误消息.但是当我将构建日志设置为详细时,它似乎找不到程序集:

无法解析此引用.无法找到程序集Windows.Foundation.FoundationContract,Version=255.255.255.255,Culture=neutral,PublicKeyToken=null".检查以确保程序集存在于磁盘上.如果您的代码需要此引用,您可能会收到编译错误.

<块引用>

文件夹和文件存在于 C:\Program Files (x86)\WindowsKits\10\References**10.0.16299.0**\Windows.Foundation.FoundationContract\3.0.0.0和 C:\Program Files (x86)\WindowsKits\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="使用: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)"><厚度 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 行代码)来找到问题,对此我有点生气:)

解决方案

你的 16299 和 15063 SDK 文件似乎有问题,你可以尝试打开文件资源管理器,到相应的文件位置查看是否SDK 已存在.

路径应该是:C:\Program Files (x86)\Windows Kits\10\References\10.0.15063.0(10.0.16299.0)\Windows.Foundation.FoundationContract\3.0.0.0\

否则,您可以尝试从 Windows SDK 和模拟器存档.

如果还是不行,也请尝试将Microsoft.NETCore.UniversalWindowsPlatform Nuget更新到最新版本,然后重启你的VS,清理并重新构建你的应用程序.顺便说一句,还请提供您的设备操作系统版本和操作系统版本,以帮助我调查此问题.

---更新---

另一种解决方法是,您可以在 标记对之后声明 ResourceDictionary 的内容.这将防止触发崩溃.

I updated one UWP App to a newer SDK and set target version to 16299 and Min Version to 15063.

Then I'm using the Windows.Foundation.UniversalApiContract Namespace to use features of the new SDK if available. Example:

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" ...

The build failed with no error message displayed. But when I set build log to detailed it seems that it won't find the assemblies:

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.

The Folder and files exist on C:\Program Files (x86)\Windows Kits\10\References**10.0.16299.0**\Windows.Foundation.FoundationContract\3.0.0.0 AND C:\Program Files (x86)\Windows Kits\10\References**10.0.15063.0**\Windows.Foundation.FoundationContract\3.0.0.0

Update 1: It seems it has to to with my resource disctionary and the acrylic brushes. If I copy my resource dictionary to a blank app the same error occurs. If I remove the contract thing and all acrylic brushes from the resource disctionary the build succeeded. So what am I missing here?

Update 2: I finally found where the issue occurs (maybe you can reproduce, just start with an blank app (Target: Fall Creators, Min Version: Creators Update), create a ResourceDictionary and copy this into it):

<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>

If I remove the first line (thickness) from the dictionary the Build succeed. My system runs on April 2018 Update, but I have the same issue on another machine with the Fall Creators Update.

Solution: I've splitted ThemeResources and Styles into two seperate ResourceDictionaries and now the build succeeded in my main project. But I do not understand why this is happening and why no exact error message appears. I've spent about 8 hours (my project has >70000 lines of code) to find the issue and I'm a little bit angry about it :)

解决方案

It seems there are some issue with your 16299 and 15063 SDK file, you can try to open the file explorer and go to the corresponding file location to see whether the SDK is existed.

The path should be: C:\Program Files (x86)\Windows Kits\10\References\10.0.15063.0(10.0.16299.0)\Windows.Foundation.FoundationContract\3.0.0.0\

Otherwise, you can try to download and install the SDK version again from the Windows SDK and emulator archive.

If this still can not work, please also try to update the Microsoft.NETCore.UniversalWindowsPlatform Nuget to the latest version then restart your VS, clean and rebuild your app again. By the way, please also provide your device OS version and OS build to help me look into this issue.

---Update---

Another workaround is that you can declare the contents of the ResourceDictionary after the <ResourceDictionary.ThemeDictionaries></ResourceDictionary.ThemeDictionaries> tag pair. This will prevent the crash from triggering.

这篇关于C# UWP 构建失败/Windows.Foundation.FoundationContract 丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆