C# 在 .NET Framework 4.6.1 中使用 Microsoft.Toolkit.Win32.UI.Controls - Web 浏览器控件升级

C# Using Microsoft.Toolkit.Win32.UI.Controls in .NET Framework 4.6.1 - Web Browser Control Upgrade

我的程序在我的程序中使用 Web 浏览器控件已经有一段时间了,但它不再削减它,因为它无法在大多数网页上与 javascript 一起正常工作。幸运的是,Microsoft has released a new web browser tool for us to use and it uses EdgeHTML powered webview. The nugget package installer here 在我的程序中不起作用。当我 运行 在程序包管理器控制台中出现此错误时

Install failed. Rolling back... Package 'Microsoft.Toolkit.Win32.UI.Controls.3.0.0' does not exist in project 'Email Analyzer' Package 'Microsoft.Toolkit.Win32.UI.Controls.3.0.0' does not exist in folder 'C:\Users\thood\Desktop\Projects\Email Analyzer\packages' Executing nuget actions took 6.64 sec Install-Package : Could not install package 'Microsoft.Toolkit.Win32.UI.Controls 3.0.0'. You are trying to install this package into a project that targets '.NETFramework,Version=v4.6.1', but the package does not contain any assembly references or content files that are compatible with that framework. For more information, contact the package author. At line:1 char:1 + Install-Package Microsoft.Toolkit.Win32.UI.Controls -Version 3.0.0 + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + CategoryInfo : NotSpecified: (:) [Install-Package], Exception + FullyQualifiedErrorId : NuGetCmdletUnhandledException,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand

此外,这是安装过程的对话

PM> Install-Package Microsoft.Toolkit.Win32.UI.Controls -Version 3.0.0 

Attempting to gather dependency information for package 'Microsoft.Toolkit.Win32.UI.Controls.3.0.0' with respect to project 'Email Analyzer', targeting '.NETFramework,Version=v4.6.1'
Gathering dependency information took 1.91 sec
Attempting to resolve dependencies for package 'Microsoft.Toolkit.Win32.UI.Controls.3.0.0' with DependencyBehavior 'Lowest'
Resolving dependency information took 0 ms
Resolving actions to install package 'Microsoft.Toolkit.Win32.UI.Controls.3.0.0'
Resolved actions to install package 'Microsoft.Toolkit.Win32.UI.Controls.3.0.0'
Retrieving package 'Microsoft.Toolkit.Win32.UI.Controls 3.0.0' from 'nuget.org'.
GET https://api.nuget.org/v3-flatcontainer/microsoft.toolkit.win32.ui.controls/3.0.0/microsoft.toolkit.win32.ui.controls.3.0.0.nupkg
OK https://api.nuget.org/v3-flatcontainer/microsoft.toolkit.win32.ui.controls/3.0.0/microsoft.toolkit.win32.ui.controls.3.0.0.nupkg 305ms
Installing Microsoft.Toolkit.Win32.UI.Controls 3.0.0.

这仅仅是因为该工具包不支持 4.6.1 吗?将我的程序回滚到 3.0.0 并不是一个真正的选择,因为我使用了对 System.Threading.Tasks 的引用,这在 3.0.0 中不可用。 运行ning 4.6.1 是否有人能够成功集成新工具包?

好的,事情就是这样,有两个步骤可以解决这个问题。希望如果其他人收到此错误,我的回答将能够为您节省一些时间。我将通过链接将其分为 2 个简单的步骤。

  1. 首先,您需要阅读 this article 了解如何更新您的框架。当您进入 "Target Framework:" 下拉菜单时,您需要 select "Install other frameworks..." 并找到并下载 运行 4.6.2。完成。

  2. 接下来,您需要查看您 运行 正在使用的 Windows 版本。按照以下步骤操作:开始 > 设置(左下角的齿轮图标)> 系统 > 关于(左面板底部)> 向下滚动到 "Windows specifications" > 检查您的版本。 如果您是 运行ning 1803,那太好了 - 您已经完成了!如果您像我一样还没有使用 1803 版本(我使用的是 1709),请转到 here 并单击 "Update Now" 将安装程序下载到您的 PC 上。找到安装程序和 运行。这将需要一段时间才能完成安装,因此请耐心等待,并在需要时插入您的 PC。

就是这样。安装后,您应该可以在 Visual Studio 4.6.2 中使用 WebViewControl!干杯!