How can I add WebView2 control in Visual Studio Toolbar?

schlebe picture schlebe · Apr 18, 2020 · Viewed 7.8k times · Source

In Visual Studio 2019, using Nuget, I have installed Microsoft.Web.WebView2 package.

PM> Install-Package Microsoft.Web.WebView2 -Version 0.9.430

As explained on Web, I have installed new Microsoft Edge Chromium Canary version (it is important).

Now, when I open the Toolbox, I don't see any WebView2 control.

Before that, I have installed WebView control (old version that is working with old Edge browser).

After installing WebView, the control has been visible immediately in Toolbox.

But this is not the case with WebView2 control.

I have tried to add in Toolbox all controls from Microsoft.Web.WebView2 package manually.

But Visual Studio refuses to load WebView2Loader.dll found in following folder

C:\Users\bernard\.nuget\packages\microsoft.web.webview2\0.9.430\build\x86

I have also tried with DLL found in

C:\Users\bernard\.nuget\packages\microsoft.web.webview2\0.9.430\build\x64

Is there possible to install WebView2 control in Toolbox ?

If yes, how ?

Answer

longestwayround picture longestwayround · Jun 13, 2020

I also had this problem. I followed the instructions in the Getting Started tutorial:

https://docs.microsoft.com/en-us/microsoft-edge/webview2/gettingstarted/winforms

and installed Canary Edge as well, but the controls were still not appearing. However, it is interesting that the Microsoft.Web.WebView2.WinForms references were not showing up in the References of my Windows Form project initially. They are now appearing, but it is not clear why any of the following steps were necessary after initially simply using Nuget to installing Canary and the latest version of the WebView2 control.

  1. After reinstalling Canary, restart Windows
  2. Clean Project
  3. In Manage Nuget packages, reinstall the WebView2 package to a lower version (I used the prelease of the current version, 0.9.538-prerelease)

After the third step, the library references to the WebView2 control appeared in my project References for the first time, and I was able to use them in the Form Designer.

NOTE: trying to update the control to the release version on 0.9.538 caused the references to disappear from the References and the WebView2 control was no longer available to the Form Designer. Reinstalling the prerelease solved the issue, so it appears the release of 0.9.538 supports a smaller scope than its prerelease.

TL;DR: do not update to the latest version of 0.9.538, just use the 0.9.538-prerelease.