【发布时间】:2016-10-14 02:49:39
【问题描述】:
我需要在 Windows 10 中从 WPF 桌面应用程序启动通用 Windows 应用程序。(实际上,我需要对通用 Windows 应用程序服务进行调用,但目前,我在启动应用程序时遇到了问题。 )
大多数情况下,我正在尝试遵循此处的示例:Launch a Universal App from a WPF App。
我能够按照代码毫无问题地创建他的 UniversalTargetApp。但是当我尝试通过将他的引用添加到 .csproj 文件来“点亮 Windows 10 功能”时,我得到了错误。
他说要把这个添加到引用 ItemGroup 中:
<!-- Light up Windows 10 features -->
<Reference Include="System.Runtime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll</HintPath>
</Reference>
<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
<SpecificVersion>False</SpecificVersion>
<HintPath>C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>
<Reference Include="Windows">
<HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd</HintPath>
</Reference>
<!-- Light up Windows 10 features -->
但是当我这样做时,我得到一个错误:
Multiple assemblies with equivalent identity have been imported: 'C:\Windows\Microsoft.NET\Framework\v4.0.30319\System.Runtime.dll' and 'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\Facades\System.Runtime.dll'. Remove one of the duplicate references.
显然,他添加对通用 Windows 程序集的引用的方法适用于他的 Windows 10 版本,否则他不会发布他的示例。但也很明显,这不是添加对通用 Windows 程序集的引用的正确方法,否则它不会损坏。
我一直在努力追查如何正确引用通用 Windows 程序集。我发现的只有这个:
How to call WinRT APIs in Windows 8 from C# Desktop Applications
但这可以追溯到 Windows 8,我无法让它在 Windows 10 中运行。
谁能告诉我引用通用 Windows 程序集的正确方法,以便我可以调用 Windows.System.Launcher.LaunchUriAsync()、创建 Windows.ApplicationModel.AppService.AppServiceConnections 等?
---已编辑---
根据 Mehrzad Chehraz 的建议,我删除了前两个引用,只留下最后一个。有了这个,我不再得到多重参考错误。但我还没有编译。
以下代码:
var options = new LauncherOptions { TargetApplicationPackageFamilyName = TargetPackageFamilyName };
bool success = await Launcher.LaunchUriAsync(uri, options);
产生错误:
Error CS4036
'IAsyncOperation<LaunchQuerySupportStatus>' does not contain a definition for 'GetAwaiter' and no extension method 'GetAwaiter' accepting a first argument of type 'IAsyncOperation<LaunchQuerySupportStatus>' could be found
(are you missing a using directive for 'System'?)
有什么想法吗?
【问题讨论】:
标签: wpf visual-studio-2015 win-universal-app