ApplicationData using in Console with UWP parameters

左心房为你撑大大i 提交于 2020-01-23 03:46:06

问题


I'm trying to follow UWP with Desktop Extension – Part 2 of UWP and WinForms desktop-bridge calling the processes and passing parameters. This example Console Program.cs code includes parameters string:

 string parameters = ApplicationData.Current.LocalSettings.Values["parameters"] as string;

But the name ApplicationData does not exists in the current context, I'm trying to find out, if I've missed some reference or it is different version of C#

I'm not sure even if it is what it requires, but adding of reference Windows.Foundation.UniversalApiContract.windmd throws another error with Values:

Error CS0012 The type 'IPropertySet' is defined in an assembly that is not referenced. You must add a reference to assembly 'Windows.Foundation.FoundationContract


回答1:


If you want to use ApplicationData class, please add Windows.winmd where in the C:\Program Files (x86)\Windows Kits\10\UnionMetadata\10.0.17134.0\Windows.winmd. Then add Windows.Storage namespace.

Detail steps

Right click project References -> Add References -> Browse(file type all file)-> select Windows.winmd




回答2:


@Nico Zhu - MSFT is correct, but I would also suggest alternative approach, which may make your life easier in the long run - the UWP APIs for desktop apps are now also distributed via NuGet as a package which takes care of referencing the right libraries for you.

It is in preview at the time of writing, so you can install as follows:

Install-Package Microsoft.Windows.SDK.Contracts -Version 10.0.18362.2002-preview

See the NuGet page for more info.



来源:https://stackoverflow.com/questions/56879926/applicationdata-using-in-console-with-uwp-parameters

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!