简体   繁体   English

如何在 XAML 岛的 WPF 中使用正确的 WindowsRuntime.dll?

[英]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.configpackages.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:所以,几个问题:

  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? 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). (还尝试将其版本更改为 4.6.0,什么也没有。尝试替换导入路径并将其设置为包文件夹,什么也没有。如果我删除它,甚至不编译项目)。
  2. In that path to the 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?我究竟做错了什么?

From the docs :文档

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.

相关问题 UWP WindowsRuntime.dll版本错误 - UWP WindowsRuntime.dll Version errors 如何在 WPF 和 XAML 群岛中使用 Windows 10 样式资源 - How to use Windows 10 style resource in WPF with XAML Islands CS1703:在Xamarin.Droid中,我应该使用位于Mono.Framework或System.Runtime中的.Net Standard windowsruntime.dll吗? - CS1703: In Xamarin.Droid, should I use the .Net Standard windowsruntime.dll located in Mono.Framework, or System.Runtime? UWP MapControl inW WPF 应用程序使用 XAML 岛 - UWP MapControl inW WPF app using XAML Islands 如何从代码背后使用WPF XAML中的属性 - How to use property in WPF XAML from codebehind 如何在WPF XAML中使用嵌套类? - How to use nested class in WPF XAML? 无法在 C++/WinRT Xaml Islands 项目中使用来自 C# WinRT 组件的 Xaml 组件 - Cannot use an Xaml component from a C# WinRT Component in C++/WinRT Xaml Islands project Windows 10 的真正最低支持版本是什么,用于在使用 Z8CBFD56512569C43ZDEDB 的 WPF 应用程序中托管 UWP 控件? - What is the true minimum supported version of Windows 10 for hosting UWP controls in a WPF application using XAML Islands? XAML 岛,尝试发布 WPF 项目时总是出错。 有同样问题的人多吗? - XAML Islands, Always get an error trying to publish the WPF Project. More people having the same issue? 如何在另一个项目中使用自定义WPF / XAML控件? - How do I use a custom WPF/XAML control in another project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM