Reputation: 207
I created a C# DLL based on .NET 4.6.1 that has a form containing an element of type Microsoft.Web.WebView2.WinForms.WebView2
. It uses the latest (as of 6/21) release version of the SDK, pulled automatically by NuGet:
<ItemGroup>
<PackageReference Include="Microsoft.Web.WebView2">
<Version>1.0.864.35</Version>
</PackageReference>
</ItemGroup>
This works like a charm when run from Visual Studio 17 as well as directly clicking on the executable in the Release or Debug folders.
My end users will have neither the SDK nor can use NuGet to get it, though, so I am installing the WebView2 runtime via a WiX installer Custom Action. The action runs the MicrosoftEdgeWebview2Setup.exe
bootstrap installer which installs the runtime. I do see the Microsoft Edge WebView2 Runtime version 91.0.864.59 installed in the Windows Apps & features panel afterwards, so the installer does work.
With all this, the installed app can no longer run the WebView2 component. It ignores the runtime entirely and when the code invokes the form containing WebView2, I see the following exception:
Could not load file or assembly 'Microsoft.Web.WebView2.WinForms, Version=1.0.864.35, Culture=neutral, PublicKeyToken=2a8ab48044d2601e' or one of its dependencies. The system cannot find the file specified.
The exception is clearly referencing the SDK and not the runtime. Looking at the release notes for SDK 1.0.864.35 for runtime support, I see: "Minimum Runtime version to load: 86.0.616.0 or newer". I have 91.0.864.59 installed so that should work.
I have only limited experience developing in Windows and this is my first C# app anywhere, so I am likely missing something fundamental. In my flailing around, I did see a few references to the WebView2Loader.dll
. It's not clear to me if that is only applicable to C++ apps or if it also has meaning for C# -- the vast majority of sample code and question and answers as of this date still focus heavily on C++ (all the deployment docs do, for instance). On the off chance that this DLL does matter for C#, I copied it to my target folder, but that did nothing.
To sum it up, how do I deploy a C# application using a WebView2 WinForm component so that it uses the Runtime rather than a NuGet-installed SDK?
Upvotes: 1
Views: 11455
Reputation: 619
If your project configuration sets UseCommonOutputDirectory
, then the webview2 dlls are not copied.
You can either remove the following line, or manually copy the dlls to your build folder.
<UseCommonOutputDirectory>true</UseCommonOutputDirectory>
Upvotes: 1
Reputation: 590
Here's what you need to do:
Solution: Install the webview2 runtime from microsoft official runtime
Reason: You need this runtime as well, just like the .net framework.
Changes: It makes a directory in: %localappdata%\Microsoft\EdgeWebView\Application\105.0.1343.33
Shipping: Include the online installer which is 1300KB with your app.
Upvotes: 0
Reputation: 1
in my case, issue was resolved by installing Microsoft edge canary
Upvotes: 0
Reputation: 207
The answer to this is that there are four DLLs that must be copied from the SDK into the installed application's .exe
directory.
WebView2Loader.dll
Microsoft.Web.WebView2.Core.dll
Microsoft.Web.WebView2.Wpf.dll
Microsoft.Web.WebView2.WinForms.dll
All four files can be found in the NuGet packages directory. This is .nuget\packages\microsoft.web.webview2\1.0.864.35
on my system.
All four were also copied into my Release
folder during the build process by some sub-process of msbuild
, but I don't know specifically what did that or if it's standard.
The installed WebView2 application will use the Runtime if and only if all four of those SDK DLLs are copied into the .exe
folder.
Upvotes: 2