Requirements: We know that after using the WebView2 control in C#, you need to install the WebView2 runtime on the machine to display and work normally, otherwise the program will report an exception. WebView2 applications rely on the WebView2 runtime on the client machine. When distributing a WebView2 application, you need to consider how to distribute and update the WebView2 runtime on client machines.
Review:
Three modes: Evergreen Runtime Distribution Mode, Evergreen Offline Standalone Installer, Fixed Version Runtime
Download Address:The hyperlink login is visible.
Evergreen runtime distribution mode
The app uses this link to programmatically download the bootloader to the client and invoke the bootloader. This approach avoids the need to use the app packaging bootstrapper. This approach relies on Microsoft's content delivery network (CDN) for bootstrapping.
The evergreen distribution pattern ensures that WebView2 applications are taking advantage of the latest WebView2 features and security updates. The evergreen distribution pattern has the following characteristics:
- WebView2 runtimeAutomatic updateswithout having to do anything. It receives the same Microsoft Edge updates as described in the Microsoft Edge Stable Channel Release Notes and the Microsoft Edge Security Briefing Release Notes.
- All WebView2 applications that use the evergreen distribution pattern use the evergreen WebView2 runtimeShare copies to save disk space。
- On eligible systems, the binaries of the Microsoft Edge and Evergreen WebView2 runtimes are hardlinked together in the same version. This link provides benefits for disk footprint, memory, and performance.
When using the Evergreen distribution mode of the WebView2 runtime, the WebView2 app assumes that the client has the latest runtime. For all apps on the client, apps cannot require a specific version of the WebView2 runtime. When a new WebView2 SDK package is released, a compatible version of the WebView2 runtime is distributed to clients. As a result, WebView2 applications can use the APIs in the latest version of the WebView2 SDK.
The WebView2 runtime bootloader is a small (MicrosoftEdgeWebview2Setup.exe Approximately 2 MB) installer. The WebView2 runtime bootloader downloads and installs the Evergreen Runtime from Microsoft servers that match the user's device architecture.
The WebView2 runtime bootloader is invoked by issuing the following command:
Evergreen offline standalone installer
As opposed to offline clients, i.e., machines that do not have access to the external network, the WebView2 Runtime Standalone Installer is a complete installer that installs the Evergreen WebView2 runtime in an offline environment.
The Evergreen standalone installer command is as follows:
Fixed version runtime
For constrained environments with strict compatibility requirements, consider using the fixed version distribution model. The fixed version distribution mode was formerly known as the bring-your-own-version distribution pattern.
In fixed version distribution mode, control when your app's WebView2 runtime is updated. Download a specific version of the WebView2 runtime and package it with the WebView2 app. The WebView2 runtime on the client is not automatically updated. Instead, the WebView2 runtime that is packaged and distributed with the updated app is regularly updated. The fixed version method does not use the registry key of the WebView2 runtime.
Fixed version binaries are over 250 MB and make the app package larger.
Download the WebView2 runtime Download a fixed version of the WebView2 runtime as a package with a file suffix address :.cab, for example:Microsoft.WebView2.FixedVersionRuntime.106.0.1370.47.x64.cabAddress:The hyperlink login is visible.
Unzip the WebView2 runtime package using the command-line command expand {path to the package} -F:* {path to the destination folder} or use a decompression tool such as WinRAR. Avoid decompressing through File Explorer, as the method may not produce the correct folder structure. For example, the command is as follows:
The C# program indicates the path to the fixed version of the binary when creating the WebView2 environment, which is specified by the environment variable, and the code is as follows:
You can see that the winform program does not use the system-installed WebView2 runtime, but uses the fixed version of the runtime that we set.
Reference:The hyperlink login is visible.
|