静态链接 WebView2 加载程序库Statically link the WebView2 loader library

你可能希望使用单个可执行文件(而不是许多文件的包)来分发应用程序。You may want to distribute your application with a single executable file, instead of a package of many files. 若要创建单个可执行文件或减小程序包的大小,应静态链接 WebView2Loader 文件。To create a single executable file, or to reduce the size of your package, you should statically link the WebView2Loader files. WebView2 SDK 包含头文件 、 WebView2Loader.dllIDL 文件。The WebView2 SDK contains a header file, WebView2Loader.dll, and the IDL file. WebView2Loader.dll 是一个小型组件,可帮助应用在设备上找到 WebView2 运行时Microsoft Edge非稳定通道。is a small component that helps apps locate the WebView2 Runtime, or non-stable channels of Microsoft Edge, on the device.

对于不希望提供 的应用, WebView2Loader.dll 请完成以下步骤。For apps that don't want to ship a WebView2Loader.dll, complete the following steps.

  1. .vcxproj 文本编辑器(如文本编辑器)中打开应用Visual Studio Code。Open the .vcxproj project file for your app in a text editor, such as Visual Studio Code.

    备注

    项目 .vcproj 文件可能是隐藏文件,这意味着它不会显示在Visual Studio。The .vcproj project file may be a hidden file, meaning it does not display in Visual Studio. 使用命令行查找隐藏文件。Use the command-line to find hidden files.

  2. 在包含 WebView2 程序包目标文件的代码中找到NuGet部分。Locate the section in the code where you include the WebView2 NuGet package target files. 代码中的位置在下图中突出显示。The location in the code is highlighted in the following figure.

    Project文件代码段

  3. 复制以下代码段并将其粘贴到包含 Microsoft.Web.WebView2.targets 位置。Copy the following code snippet and paste it where the Microsoft.Web.WebView2.targets is included.

    <PropertyGroup> 
        <WebView2LoaderPreference>Static</WebView2LoaderPreference> 
    </PropertyGroup>
    

    插入的代码段

  4. 编辑应用生成配置的其他依赖项。Edit the additional dependencies of the build configuration for your app. 首先,查找所有 <AdditionalDependencies> 标记。To begin, find all of the <AdditionalDependencies> tags. 对于每个版本 version.lib ,将 作为附加依赖项添加到文件中每个不同的生成 .vcxproj 配置。For each, add version.lib as an additional dependency to every different build configuration in the .vcxproj file.

    将 version.lib 添加到 ItemDefinitionGroups

    备注

    WebView2 团队旨在在未来版本中自动添加其他依赖项。The WebView2 team aims to automate adding the additional dependency in future releases.

  5. 编译并运行应用。Compile and run your app.

与 WebView2 团队联系Getting in touch with the WebView2 team

分享反馈以帮助构建更丰富的 WebView2 体验。Share your feedback to help build richer WebView2 experiences. 若要提交功能请求或 Bug,或搜索已知问题,请导航到 Microsoft Edge WebView 反馈 存储库。To submit feature requests or bugs, or search for known issues, navigate to the Microsoft Edge WebView feedback repo.

另请参阅See also