Solution file: not provided in the repo. You create a solution file in the steps below.
To demonstrate how to deploy the Evergreen WebView2 Runtime with your app, this article describes how to use the Microsoft Visual Studio Installer Project extension for Visual Studio. You create a project of type Setup Project, to create an installer for the Win32 sample app (WebView2APISample). That installer that you create chain-installs the Evergreen WebView2 Runtime.
You first edit the project.xml file from the repo, and then in Visual Studio, you create a new project by using the Setup Project project template from the Microsoft Visual Studio Installer Projects extension.
This sample demonstrates several different deployment approaches:
Downloading the Evergreen WebView2 Runtime Bootstrapper by using a link.
Packaging the Evergreen WebView2 Runtime Bootstrapper with your app.
Packaging the Evergreen WebView2 Runtime Standalone Installer with your app.
To become familiar with the app that this sample distributes, and to make sure your environment is set up for general Win32 WebView2 app development, build and run the Win32 sample app (WebView2APISample) before using this deployment sample.
Do the steps in Win32 sample app (WebView2APISample) and then continue below.
Prerequisite: As stated in the above page, Microsoft Visual Studio is required, including C++ support. Microsoft Visual Studio Code is not supported for this WV2DeploymentVSInstallerSample sample.
The above page helps you clone or download the WebView2Samples repo, and install Visual Studio with C++ support, if not done yet.
Step 2 - Install Visual Studio Installer Projects
If not done yet, install Visual Studio Installer Projects:
Install the Microsoft Visual Studio Installer Projects for Visual Studio 2019. Follow the steps on that page, and then return to this page and continue the steps below.
If a Waiting on the following processes to shut down dialog appears, close Visual Studio.
Step 3 - Edit product.xml to configure how to distribute the WebView2 Runtime
Open Visual Studio. In the opening screen, you can click the Continue without code link in the lower right.
Open the following individual file that's in your local copy of the repo: <repo-location>\WebView2Samples\SampleApps\WV2DeploymentVSInstallerSample\product.xml
Inspect product.xml. There are three <PackageFile> lines. Study the comment above each of the 3 lines. Here is a simplified view of the lines, with clarifications.
The first <PackageFile> line uses file MicrosoftEdgeWebview2Setup.exe, which is the Evergreen WebView2 Runtime Bootstrapper, and it specifies a HomeSite website. Use this line for Approach 1: Downloading the Evergreen WebView2 Runtime Bootstrapper through a link:
XML
<!-- Download the MicrosoftEdgeWebview2Setup.exe --><!-- <PackageFile Name="MicrosoftEdgeWebview2Setup.exe" HomeSite="WebViewRuntime" PublicKey="..."/> -->
The second <PackageFile> line uses file MicrosoftEdgeWebview2Setup.exe, which is the Evergreen WebView2 Runtime Bootstrapper. Use this line for Approach 2: Packaging the Evergreen WebView2 Runtime Bootstrapper with the app:
XML
<!-- Package the MicrosoftEdgeWebview2Setup.exe --><PackageFileName="MicrosoftEdgeWebview2Setup.exe" />
The third <PackageFile> line uses file MicrosoftEdgeWebView2RuntimeInstallerX64.exe, which is a platform-specific Evergreen WebView2 Runtime Standalone Installer. Use this line for Approach 3: Packaging the Evergreen WebView2 Runtime Standalone Installer with your app:
Identify which approach you are using. Approach 2 is the default; that is, the line to use Approach 2 is un-commented in the repo's product.xml file.
Edit product.xml, as follows; do the steps in one of the three sections below.
Approach 1: Downloading the Evergreen WebView2 Runtime Bootstrapper through a link
If you want the app to download the Evergreen WebView2 Runtime Bootstrapper (MicrosoftEdgeWebview2Setup.exe) through a link:
Within the <PackageFiles CopyAllPackageFiles="false"> section, un-comment the following line (keep the long public key value), and comment out the other lines:
The PublicKey value for the WebView2 Runtime Bootstrapper may change without notice. We're working on addressing this issue. For now, you may need to replace it in product.xml with an updated PublicKey value.
Within the <Commands Reboot="Defer"> and </Commands> section, make sure PackageFile points to "MicrosoftEdgeWebview2Setup.exe" so that the Visual Studio installer is using the Bootstrapper.
Save the file.
Approach 2: Packaging the Evergreen WebView2 Runtime Bootstrapper with the app
If you want to package the Evergreen WebView2 Runtime Bootstrapper (MicrosoftEdgeWebview2Setup.exe) with the app:
Within the <PackageFiles CopyAllPackageFiles="false"> section, un-comment the following line and comment out the other lines:
Within the <Commands Reboot="Defer"> section, make sure PackageFile points to "MicrosoftEdgeWebview2Setup.exe" so that the Visual Studio installer is using the Bootstrapper.
Save the file.
Approach 3: Packaging the Evergreen WebView2 Runtime Standalone Installer with your app
If you want to package the Evergreen WebView2 Runtime Standalone Installer with the app:
Within the <PackageFiles CopyAllPackageFiles="false"> section, un-comment the following line and comment out the other lines:
Within the <Commands Reboot="Defer"> and </Commands> section, make sure PackageFile points to "MicrosoftEdgeWebView2RuntimeInstallerX64.exe" so that the Visual Studio installer is using the Standalone Installer.
If you're targeting non-X64 devices, edit the MicrosoftEdgeWebView2RuntimeInstallerX64 file name to reflect the correct architecture.
Save the file.
Step 4 - Download the WebView2 Bootstrapper or Standalone Installer
If you want to package either the Bootstrapper (Approach 2) or the Standalone Installer (Approach 3) with the app, do the steps in this section. Otherwise skip to the next major Step section.
Save the downloaded Bootstrapper or the Standalone Installer under the <repo-location>\WebView2Samples\SampleApps\WV2DeploymentVSInstallerSample\ folder.
Step 5 - Copy the WV2DeploymentVSInstallerSample folder into a Packages folder
This step applies to all of the approaches (1, 2, or 3).
Copy the <repo-location>\WebView2Samples\SampleApps\WV2DeploymentVSInstallerSample\ folder, and paste it into either one of the following folders:
In Visual Studio, select File > New > Project. The Create a new project window appears.
In the Search for templates text box, enter setup project, and then select the Setup Project template. Make sure you select the template that's named exactly that, as shown below:
Click the Next button.
The Configure your new project: Setup Project dialog opens, as shown below.
In the Project name text box, enter a name, such as MyWin32WV2DeploySample.
In the Location text box, navigate to a location that's not inside another project directory, such as <repo-path>\WebView2Samples\ or a location that's not in the repo directory.
Click the Create button.
Step 7 - Add WebView2 Runtime as a prerequisite
In Visual Studio, in Solution Explorer, right-click your project, and then select Properties. The Property Pages dialog opens.
Erfahren Sie, wie Sie Azure App Service zum Erstellen einer neuen auf ASP.NET basierten Web-App verwenden können und diese anschließend über Visual Studio veröffentlichen und aktualisieren.
Richten Sie Ihre Entwicklungsumgebung für die WebView2-Entwicklung ein. Richten Sie Git, Visual Studio und einen Vorschaukanal von Microsoft Edge ein, und klonen Sie das WebView2Samples-Repository.
Beispiel-Apps für WebView2, für verschiedene Frameworks oder Plattformen, einschließlich WinUI 2 (UWP), WinUI 3 (Windows App SDK), WPF, WPF mit Chrome DevTools-Protokollerweiterung, WinForms, Win32/C++ und Win32 mit visueller Komposition.
Übersicht über die Zusammenarbeit der webView2-Klassen oder -Schnittstellen der obersten Ebene: CoreWebView2Environment, CoreWebView2Controller und CoreWebView2.