如何在WPF中为XAML群岛使用正确的WindowsRuntime.dll? [英] How to use the correct WindowsRuntime.dll in WPF for XAML Islands?
问题描述
我正在开发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.
那么,有几个问题:
-
MyProject.csproj
文件中的每个引用都是从packages
文件夹添加的,但此WindowRuntime
除外,它来自程序文件(上面的路径)),为什么没有从packages
文件夹中引用?(也尝试将其版本更改为4.6.0,什么也没有.尝试替换导入路径并将其设置到packages文件夹,什么也没有.如果删除它,甚至不会编译项目.) - 在
Program Files
中的WindowsRuntime.dll
的路径中,什么是.NetCore \ v4.5 \
,但是最新版本.NetCore是3.1吗?它包含一个WindowsRuntime.dll
版本4.0.0,为什么?
- Every reference in
MyProject.csproj
file is added from thepackages
folder, except thisWindowRuntime
, which is from Program Files (path above), why is that not referenced from thepackages
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). - In that path to the
WindowsRuntime.dll
inProgram Files
what is that.NetCore\v4.5\
, however the latest .NetCore is 3.1? And it contains aWindowsRuntime.dll
version 4.0.0, why?
我在做什么错了?