如何在WPF中为XAML群岛使用正确的WindowsRuntime.dll? [英] How to use the correct WindowsRuntime.dll in WPF for XAML Islands?

查看:84
本文介绍了如何在WPF中为XAML群岛使用正确的WindowsRuntime.dll?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发WPF应用程序,我想添加 XAML Islands 以便能够在我的应用程序中使用Windows 10控件.以下教程我通过Nuget软件包管理器添加了 Microsoft.Toolkit.Wpf.UI.XamlHost 项目.它还安装了它的依赖项,例如 Microsoft.Windows.SDK.Contracts(10.0.18362.2005),它依赖于 System.Runtime.WindowsRuntime> = 4.6.0 .当我运行项目时,出现以下编译错误:

I'm developing a WPF application and I would like to add XAML Islands to be able to use windows 10 controls in my app. Following this tutorial I added the Microsoft.Toolkit.Wpf.UI.XamlHost project via Nuget Package Manager. It also installed it's dependencies, like Microsoft.Windows.SDK.Contracts (10.0.18362.2005), which has a dependency to System.Runtime.WindowsRuntime >= 4.6.0. When I run the project, the following compilation error appeared:

Multiple assemblies with equivalent identity have been imported: 
'C:\Users\*[path to my project]*\packages\System.Runtime.WindowsRuntime.4.6.0\ref\netstandard2.0\System.Runtime.WindowsRuntime.dll'
and 
'C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll'.
Remove one of the duplicate references.

清除错误消息,XamlHost安装了它的依赖项(它修改了 app.config packages.config 文件-确切的行在下面发布),我也有默认情况下,通过以下方法将WindowsRuntime.dll添加到 MyProject.csproj 文件中:

Clear error message, the XamlHost installed it's dependencies (it modified the app.config and packages.config files - the exact rows are posted below) and I also have a WindowsRuntime.dll added by default in MyProject.csproj file the following way:

<Reference Include="System.Runtime.WindowsRuntime, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089, processorArchitecture=MSIL">
    <SpecificVersion>False</SpecificVersion>
    <HintPath>C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETCore\v4.5\System.Runtime.WindowsRuntime.dll</HintPath>
</Reference>

因此,我离开了XamlHost当前安装的依赖项,并删除了我上面发布的默认依赖项.然后,当我编译它时,抛出一个错误弹出窗口:此应用程序由于应用程序配置不正确而无法启动.我还尝试删除了另一个导入,该导入是在安装XamlHost项目时添加的.:

So I left the dependencies currently installed with XamlHost and removed the default one, what I posted above. Then, when I compiled it threw an error popup that: This application has failed to start because the application configuration is incorrect. I also tried to remove the other import, which was added when I installed the XamlHost project:

因此,从 app.config 中删除了以下几行:

So, removed from the app.config the following lines:

<dependentAssembly>
    <assemblyIdentity name="System.Runtime.WindowsRuntime" publicKeyToken="b77a5c561934e089" culture="neutral" />
    <bindingRedirect oldVersion="0.0.0.0-4.6.0.0" newVersion="4.6.0.0" />
</dependentAssembly>

并来自 packages.config :

<package id="System.Runtime.WindowsRuntime" version="4.6.0" targetFramework="net471" />

但是它抛出了相同的弹出窗口,表明项目配置不正确.

But it threw the same popup, that the project configuration is incorrect.

还更新到最新的Visual Studio(我正在使用vs2019社区),更新到最新的Windows SDK和最新的.NET Framework.

Also updates to the latest Visual studio (I'm using vs2019 Community), updated to the latest windows SDK, and to the latest .NET Framework.

那么,有几个问题:

  1. MyProject.csproj 文件中的每个引用都是从 packages 文件夹添加的,但此 WindowRuntime 除外,它来自程序文件(上面的路径)),为什么没有从 packages 文件夹中引用?(也尝试将其版本更改为4.6.0,什么也没有.尝试替换导入路径并将其设置到packages文件夹,什么也没有.如果删除它,甚至不会编译项目.)
  2. Program Files 中的 WindowsRuntime.dll 的路径中,什么是 .NetCore \ v4.5 \ ,但是最新版本.NetCore是3.1吗?它包含一个 WindowsRuntime.dll 版本4.0.0,为什么?
  1. Every reference in MyProject.csproj file is added from the packages folder, except this WindowRuntime, which is from Program Files (path above), why is that not referenced from the packages folder? (Also tried to change it's version to 4.6.0, nothing. Tried to replace the import path and set it to the packages folder, nothing. If I remove it, doesn't even compile the project).
  2. In that path to the WindowsRuntime.dll in Program Files what is that .NetCore\v4.5\, however the latest .NetCore is 3.1? And it contains a WindowsRuntime.dll version 4.0.0, why?

我在做什么错了?

推荐答案

在以 .NET Core 3.x 为目标的WPF和Windows Forms应用程序中,仅 支持使用XAML Islands托管WinRT XAML控件.面向.NET Framework的应用程序不支持XAML孤岛.

Using XAML Islands to host WinRT XAML controls is supported only in WPF and Windows Forms apps that target .NET Core 3.x. XAML Islands are not supported in apps that target the .NET Framework.

从项目文件的格式以及您仍在使用 packages.config 文件的事实来看,似乎您的目标是.NET Framework.不支持.

Judging by the format of your project file and the fact that you are still using a packages.config file, it seems like you are targeting the .NET Framework. This is not supported.

这篇关于如何在WPF中为XAML群岛使用正确的WindowsRuntime.dll?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆