从WPF启动通用Windows应用程序

问题描述:

我需要从Windows 10中的WPF桌面应用程序启动通用Windows应用程序。(实际上,我需要针对通用Windows应用程序服务进行调用,但目前,我正在刚刚启动应用程序的问题。)从WPF启动通用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'?) 

任何想法?

删除前两个参考节点,只保留最后一个:以这种方式

<!-- Light up Windows 10 features --> 
<Reference Include="Windows"> 
    <HintPath>C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd</HintPath> 
</Reference> 
<!-- Light up Windows 10 features --> 

Launcher.LaunchUriAsync的作品,但没有测试AppServiceConnection

我发现这里的部分答案:

Load UWP library into .NET Framework app

第1步:加入。的csproj文件

<PropertyGroup> 
    <TargetPlatformVersion>10.0</TargetPlatformVersion> 
</PropertyGroup> 

步骤2:添加参考

C:\Program Files (x86)\Windows Kits\10\UnionMetadata\Windows.winmd 

步骤3:添加参考

C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll