Uwp 如何在CONSOLAPP中添加对Windows .Fastual.Basic合同的引用来解析Type IPropertySet

Uwp 如何在CONSOLAPP中添加对Windows .Fastual.Basic合同的引用来解析Type IPropertySet,uwp,visual-studio-2017,.net-4.6.1,Uwp,Visual Studio 2017,.net 4.6.1,这感觉像是一个真正的新手错误 我有一个ConsoleApp,作为UWP解决方案的一部分使用(如中所述)。在ConsoleApp项目(不是UWP项目)中有以下代码行 string parameters = ApplicationData.Current.LocalSettings.Values["exampleSetting"] as string; …但在我的代码中,Visual Studio表示对于值 IPropertySet类型是在未引用的部件中定义的 VisualStudio建议我参考

这感觉像是一个真正的新手错误

我有一个ConsoleApp,作为UWP解决方案的一部分使用(如中所述)。在ConsoleApp项目(不是UWP项目)中有以下代码行

string parameters = ApplicationData.Current.LocalSettings.Values["exampleSetting"] as string;
…但在我的代码中,Visual Studio表示对于

IPropertySet类型是在未引用的部件中定义的


VisualStudio建议我参考Wime.Studio.Basic合同。该页称它是Windows .Fastual.DLL、Windows .DLL程序集的一部分。我找到了这个副本(C:\Windows\assembly\NativeImages\U v4.0.30319\U 32\Windows.Foundation\870ea1ce5e024b92ef1b64ebeeb38cc7),但引用它时有点不对劲。

啊,所以我注意到,如果我打开
LocalSettings
打开的定义顶部有这个

#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:\程序文件(x86)\ Windows工具包\ 10引用,发现了<强> Windows .Frase.Fuffic Stuts文件夹。没有DLL,但是如果您将VisualStudio参考对话框切换到“所有文件类型”,我可以使用<强> Windows .Fase.Fuffic < WINMD <强>文件(在C:\程序文件(x86)\ Windows工具包\ 10 \引用\WINDOWS .Frase.Fuffic Currest\2.0.0.0)中添加引用。p>


我的代码现在可以编译并运行了。但仍然无法100%确定这是否是解决此问题的正确方法。

我刚才遇到了这个问题:这是一个旧式的(pre-
)C#项目,它引用了
*.winmd
文件,其中包含一个
,是针对上一个安装了稍旧版本Windows SDK的开发人员的机器

有两种修复方法:

快速解决方案: 快速修复方法是更新
以指向机器上相同的
.winmd
文件,我建议使用类似的工具查找相同
.winmd
文件的新文件名

我的
csproj
最初有:

<Reference Include="Windows"> 
    <HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd</HintPath> 
</Reference> 
<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> 
<Private>False</Private> 
</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> 
<Private>False</Private> 
</Reference>

C:\Program Files(x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1629 .0\Windows。
假的
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1629 .0\Windows。
假的
我把它改成这样:

<Reference Include="Windows">
    <HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd</HintPath>
</Reference>
<Reference Include="Windows.Foundation.FoundationContract">
    <HintPath>C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0\Windows.Foundation.FoundationContract\4.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath>
</Reference>
<Reference Include="Windows.Foundation.UniversalApiContract">
    <HintPath>C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0\Windows.Foundation.UniversalApiContract\10.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
</Reference>

C:\Program Files(x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1941.0\Windows .Fase.基础合同\4.0.0.0 \WINDOWS .BASIC .基础合同.
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1941.0\Windows .Fun.UnvialSalpCopStudia\0.0.0.0\WINDOWIN.BING.UnvialSalpCopTrac.WINMD
更好的解决方案: 长期解决方案是,使用不同机器的用户仍然可以构建项目:

<Reference Include="Windows"> 
    <HintPath Condition="Exists('C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd')">C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd</HintPath>
    <HintPath Condition="Exists('C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd')">C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd</HintPath> 
</Reference> 
<Reference Include="Windows.Foundation.FoundationContract"> 
    <HintPath Condition="Exists('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.FoundationContract\3.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath> 
    <HintPath Condition="Exists('C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0\Windows.Foundation.FoundationContract\4.0.0.0\Windows.Foundation.FoundationContract.winmd')">C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0\Windows.Foundation.FoundationContract\4.0.0.0\Windows.Foundation.FoundationContract.winmd</HintPath> 
</Reference> 
<Reference Include="Windows.Foundation.UniversalApiContract"> 
    <HintPath Condition="Exists('C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd')">C:\Program Files (x86)\Windows Kits\10\References\10.0.16299.0\Windows.Foundation.UniversalApiContract\5.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
    <HintPath Condition="Exists('C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0\Windows.Foundation.UniversalApiContract\10.0.0.0\Windows.Foundation.UniversalApiContract.winmd')">C:\Program Files (x86)\Windows Kits\10\References\10.0.19041.0\Windows.Foundation.UniversalApiContract\10.0.0.0\Windows.Foundation.UniversalApiContract.winmd</HintPath>
</Reference>

C:\Program Files(x86)\Windows Kits\10\UnionMetadata\10.0.16299.0\Windows.winmd
C:\Program Files(x86)\Windows Kits\10\UnionMetadata\10.0.19041.0\Windows.winmd
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1629 .0\Windows。
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1941.0\Windows .Fase.基础合同\4.0.0.0 \WINDOWS .BASIC .基础合同.
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1629 .0\Windows。
C:\程序文件(x86)\ Windows工具包\ 10 \引用\\0.0.1941.0\Windows .Fun.UnvialSalpCopStudia\0.0.0.0\WINDOWIN.BING.UnvialSalpCopTrac.WINMD