[英]How to use the correct WindowsRuntime.dll in WPF for XAML Islands?
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.我正在开发一个 WPF 应用程序,我想添加
XAML Islands
以便能够在我的应用程序中使用 Windows 10 控件。 Following this tutorial I added the Microsoft.Toolkit.Wpf.UI.XamlHost
project via Nuget Package Manager.按照本教程,我通过 Nuget 包管理器添加了
Microsoft.Toolkit.Wpf.UI.XamlHost
项目。 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
.它还安装了它的依赖项,例如
Microsoft.Windows.SDK.Contracts (10.0.18362.2005)
,它依赖于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.
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:清除错误消息,XamlHost 安装了它的依赖项(它修改了
app.config
和packages.config
文件 - 下面发布了确切的行)并且我还在MyProject.csproj
文件中默认添加了一个 WindowsRuntime.dll,方法如下:
<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>
So I left the dependencies currently installed with XamlHost and removed the default one, what I posted above.因此,我保留了当前与 XamlHost 一起安装的依赖项,并删除了我在上面发布的默认依赖项。 Then, when I compiled it threw an error popup that:
This application has failed to start because the application configuration is incorrect.
然后,当我编译它时抛出一个错误弹出窗口:
This application has failed to start because the application configuration is incorrect.
, 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:我还尝试删除安装 XamlHost 项目时添加的其他导入:
So, removed from the app.config
the following lines:因此,从
app.config
删除了以下几行:
<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>
and from packages.config
:和来自
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.但它抛出了相同的弹出窗口,即项目配置不正确。
Also updates to the latest Visual studio (I'm using vs2019 Community), updated to the latest windows SDK, and to the latest .NET Framework.还更新到最新的 Visual Studio(我使用的是 vs2019 社区),更新到最新的 Windows SDK,以及最新的 .NET Framework。
So, couple of questions:所以,几个问题:
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? MyProject.csproj
文件中的每个引用都是从packages
文件夹中添加的,除了这个WindowRuntime
,它来自 Program Files(上面的路径),为什么没有从packages
文件夹中引用? (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). WindowsRuntime.dll
in Program Files
what is that .NetCore\\v4.5\\
, however the latest .NetCore is 3.1?Program Files
WindowsRuntime.dll
路径中.NetCore\\v4.5\\
是什么,但是最新的 .NetCore 是 3.1? And it contains a WindowsRuntime.dll
version 4.0.0, why?WindowsRuntime.dll
版本 4.0.0,为什么? What am I doing wrong?我究竟做错了什么?
Using XAML Islands to host WinRT XAML controls is supported only in WPF and Windows Forms apps that target .NET Core 3.x .
仅在面向.NET Core 3.x 的WPF 和 Windows 窗体应用程序中支持使用 XAML 岛托管 WinRT XAML 控件。 XAML Islands are not supported in apps that target the .NET Framework.
面向 .NET Framework 的应用不支持 XAML 岛。
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.从您的项目文件格式以及您仍在使用
packages.config
文件这一事实来看,您似乎是针对 .NET Framework 的。 This is not supported.这不受支持。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.