Skip to content

Quick Start For MS .Net 4.x

Alex Maitland edited this page Sep 27, 2022 · 6 revisions

For those targeting MS .Net 4.5.2, .Net 4.6.x, .Net 4.7.x and .Net 4.8

1.0 Install Nuget Packages

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

  • CefSharp.WinForms
  • CefSharp.Wpf
  • CefSharp.OffScreen

2.0 AnyCPU (Optional)

  • 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.

3.0 Read the Docs

  • 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.

4.0 Add app.manifest to your application

5.0 Add ChromiumWebBrowser to your application.

Implementation Example
WPF 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>
WinForms For WinForms use CefSharp.WinForms.ChromiumWebBrowser
using CefSharp;
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");
OffScreen For OffScreen use CefSharp.OffScreen.ChromiumWebBrowser
using CefSharp;
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");

5.1 Execute some JavaScript (optional)

// Add usage statement to access additional functionality
// e.g. EvaluateScriptAsync
using CefSharp;
var response = await browser.EvaluateScriptAsync("1 + 1");
if(response.Success)
{
    var result = response.Result;
}