Skip to content
Alex Maitland edited this page Feb 14, 2022 · 47 revisions

To get started with CefSharp checkout the CefSharp.MinimalExample project here on GitHub. The project contains basic working examples of the WinForms, WPF and OffScreen versions.

Installation (MS .Net 4.5.2, .Net 4.6.x, .Net 4.7.x and .Net 4.8)

  • Install one of the following via the Nuget Package Manager from within Visual Studio

    • CefSharp.WinForms
    • CefSharp.Wpf
    • CefSharp.OffScreen
  • Review the Post Installation steps in the Readme.txt file that's opened in Visual Studio upon installation.

  • Review the Release Notes for the version you just installed, a list of Known Issues for the problems we're currently aware of.

  • Check out the API Doc, it's version specific, make sure you pick the correct version.

  • When targeting AnyCPU with Prefer32bit = true then no further action is required. Your application is 32bit and will include the 32bit binaries/resources.

  • When targeting AnyCPU please see https://github.com/cefsharp/CefSharp/issues/1714. The MinimalExample demos AnyCPU support and can be used as a reference.

  • For architecture specific builds then set your PlatformTarget to x86 or x64.

Installation (MS .Net Core 3.1/.Net 5.0/.Net 6.0)

  • Install one of the following via the Nuget Package Manager from within Visual Studio
    • CefSharp.WinForms.NETCore
    • CefSharp.Wpf.NETCore
    • CefSharp.OffScreen.NETCore

I strongly suggest setting a RuntimeIdentifier. I've done my best to make the packages work when no RuntimeIdentifier is specified, there are use cases when you will need to specify a <RuntimeIdentifier/> for the packages to work correctly.

Specify a RuntimeIdentifier. Use one of the following in your proj file.

<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x86</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
<!-- Will default to your current machine architecture, in most cases this will be win-x64 -->
<RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">$(NETCoreSdkRuntimeIdentifier)</RuntimeIdentifier>

<!--
You should also set
SelfContained = false (otherwise the whole .Net Framework will be included in your bin folder
-->
<SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>

Without a RuntimeIdentifier the required files will hopefully be copied to the output folder, as I said there are likely cases where it won't work.

If your proj file specifies multiple platforms e.g. <Platforms>x86;x64</Platforms> then I'd suggest using the following:

<PropertyGroup Condition="'$(PlatformTarget)' == 'x86'">
  <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x86</RuntimeIdentifier>
  <SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>

<PropertyGroup Condition="'$(PlatformTarget)' == 'x64'">
  <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-x64</RuntimeIdentifier>
  <SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>

<PropertyGroup Condition="'$(PlatformTarget)' == 'arm64'">
  <RuntimeIdentifier Condition="'$(RuntimeIdentifier)' == ''">win-arm64</RuntimeIdentifier>
  <SelfContained Condition="'$(SelfContained)' == ''">false</SelfContained>
</PropertyGroup>

SelfPublish and SelfContained

You will need to self host the BrowserSubProcess using your main application executable. See https://github.com/cefsharp/CefSharp/issues/3407 for details

  • Review the Post Installation steps in the Readme.txt file that's opened in Visual Studio upon installation.
  • Review the Release Notes for the version you just installed, a list of Known Issues for the problems we're currently aware of.
  • Check out the API Doc, it's version specific, make sure you pick the correct version.

Code Examples

  • Add a new instance of the browser
    • For WPF use CefSharp.Wpf.ChromiumWebBrowser
      <!-- Add a xmlns:wpf="clr-namespace:CefSharp.Wpf;assembly=CefSharp.Wpf" attribute to your parent control -->
      <!-- Create a new instance in code or in `xaml` -->
      <Border Grid.Row="1" BorderBrush="Gray" BorderThickness="0,1">
          <wpf:ChromiumWebBrowser x:Name="Browser" Address="www.google.com"/>
      </Border>
    • For WinForms use CefSharp.WinForms.ChromiumWebBrowser
      using CefSharp.WinForms;
      //Create a new instance in code or add via the designer
      var browser = new ChromiumWebBrowser("www.google.com");
      parent.Controls.Add(browser);
      
      //Load a different url
      browser.LoadUrl("https://github.com");
    • For OffScreen use CefSharp.OffScreen.ChromiumWebBrowser
      using CefSharp.OffScreen;
      //Create a new instance in code
      var browser = new ChromiumWebBrowser("www.google.com");
      
      //Load a different url
      browser.LoadUrl("https://github.com");

TODO: Improve formatting, anyone with a GitHub account can help improve this wiki. Please help out!


Third-Party Articles

The following articles are unfortunately outdated, if you have written a new up to date article please include a link to it here.

WinForms C#

WinForms VB.Net

WPF C#

WPF VB.Net

  • Quick Start Guide (This guide is outdated, if someone has a newer one please add a link).