19

WebView2简单试用(四)—— 使用固定版本的Edge Runtime

 4 years ago
source link: https://www.cnblogs.com/TianFang/p/14354812.html
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Edge Runtime支持两种模式:长绿(All Green)和固定版本(Fixed Version)这两种方式和vc runtime安装比较类似。 长绿版本可以作为独立的安装包安装,所有程序共享。固定版本则也可以直接在程序中包含。

长绿版本的优势:

  1. 可以自动更新
  2. 支持在线和离线安装
  3. 所有WebView2程序共享运行时,节约磁盘空间    

固定版本的优势:

  1. 可防止版本升级到来的兼容性问题
  2. 可防止运行时被意外卸载
  3. 可和应用程序集成在一起

之前都是使用的All Green模式,本文这里介绍下Fixed Version模式的集成方法。

下载Runtime

  1. 打开Edge WebView Runtime下载页面,下载下载固定版本(Fixed Version),可以选择不同的版本和cpu架构。下载后,会得到一个几十兆的cab文件
  2. 解压cab文件至指定文件夹:expand xxxxx.cab -f:* r:\webview2

配置WebView

初始化程序的时候,指定该路径:(WPF示例)

    var env = await CoreWebView2Environment.CreateAsync(@"R:\WebView2");
    await webView.EnsureCoreWebView2Async(env);

通过这种方式,可以把runtime和应用程序集成在一起。不过,这种模式下,某些API使用会出问题,如: CoreWebView2.Environment.BrowserVersionString(不知道是否是bug)。

参考文档:

使用 WebView2 的应用分发


Recommend

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK