2016-06-13 120 views
0

我需要從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'?) 

任何想法?

回答

0

刪除前兩個參考節點,只保留最後一個:以這種方式

<!-- 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

0

我發現這裏的部分答案:

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