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. To create a single executable file, or to reduce the size of your package, you should statically link the WebView2Loader files. The WebView2 SDK contains a header file, WebView2Loader.dll, and the IDL file. WebView2Loader.dll is a small component that helps apps locate the WebView2 Runtime, or non-stable channels of Microsoft Edge, on the device.

For apps that don't want to ship a WebView2Loader.dll, complete the following steps.

  1. Open the .vcxproj project file for your app in a text editor, such as Visual Studio Code.

    Note

    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. 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 Files code snippet

  3. Copy the following code snippet and paste it where the Microsoft.Web.WebView2.targets is included.

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

    Inserted code snippet

  4. Edit the additional dependencies of the build configuration for your app. To begin, find all of the <AdditionalDependencies> tags. For each, add version.lib as an additional dependency to every different build configuration in the .vcxproj file.

    Adding version.lib to ItemDefinitionGroups

    Note

    The WebView2 team aims to automate adding the additional dependency in future releases.

  5. Compile and run your app.

Getting in touch with the WebView2 team

Share your feedback to help build richer WebView2 experiences. To submit feature requests or bugs, or search for known issues, navigate to the Microsoft Edge WebView feedback repo.

See also