这感觉像是一个真正的菜鸟错误。
我有一个 ConsoleApp,我将其用作 UWP 解决方案的一部分(如 this series of posts 中所述)。在 ConsoleApp 项目(不是 UWP 项目)中有这行代码...
string parameters = ApplicationData.Current.LocalSettings.Values["exampleSetting"] as string;
...但在我的代码中,Visual Studio 表示对于 Values ...
The Type IPropertySet is defined in an assembly that is not referenced.
Visual Studio 建议我引用 Windows.Foundation.FoundationContract。 Windows.Foundation Namespace页面说它是 Windows.Foundation.dll、Windows.dll 程序集的一部分。我找到了这个副本 (C:\Windows\assembly\NativeImages_v4.0.30319_32\Windows.Foundation\870ea1ce5e024b92ef1b64ebeeb38cc7) 但引用它闻起来不对。
最佳答案
啊,所以我注意到如果我在 LocalSettings
上按 F12,打开的定义的顶部有这个...
#region Assembly Windows.Foundation.UniversalApiContract, Version=3.0.0.0, Culture=neutral, PublicKeyToken=null, ContentType=WindowsRuntime
// C:\Program Files (x86)\Windows Kits\10\References\Windows.Foundation.UniversalApiContract\3.0.0.0\Windows.Foundation.UniversalApiContract.winmd
#endregion
所以我浏览到 C:\Program Files (x86)\Windows Kits\10\References 并找到了 Windows.Foundation.FoundationContract 文件夹。没有 dll,但如果您将 visual studio 引用对话框切换到“所有文件类型”,我可以使用 Windows.Foundation.FoundationContract.winmd 文件添加引用,(在 C:\Program Files (x86)\Windows 套件\10\References\Windows.Foundation.FoundationContract\2.0.0.0)。
我的代码现在可以编译和运行了。不过,仍然不能 100% 确定这是否是解决此问题的正确方法。
关于uwp - 如何在 ConsoleApp 中添加对 Windows.Foundation.FoundationContract 的引用以解析类型 IPropertySet,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54602250/