Skip to content
Alex Maitland edited this page Apr 26, 2017 · 9 revisions

This page is not actively maintained.

Running CefSharp for the First Time

This guide will show how to get a WinForms or WPF example app running for the first time with a CEF embedded browser. An embedded browser certainly isn't the only way CEF can be used, but is a good way to verify you have a minimal setup to get CefSharp working.

Included in the repository are two Visual Studio projects which are good examples of how to leverage CefSharp: CefSharp.WinForms.Example and CefSharp.WPF.Example

It is not necessary to build CefSharp from source, as there are NuGet packages available. However, we will build from source since the example projects are part of the same Visual Studio solution and have the necessary references already setup. See Building CefSharp for list of supported versions of Visual Studio.

Install VC 2012/2013 Redistributable Package x86

CefSharp 45.0 and later requires VC 2013 Redistributable Package x86 be installed.

Earlier versions require VC 2012 Redistributable Package x86.

Download Source Code

Since the source code repository is constantly changing, at any given time it may contain changes that might have temporarily broken the examples, so we'll instead download a specific tagged set of source code.

From the main CefSharp GitHub page click the branch:master dropdown and switch to the Tags tab. Select a tag and the page should refresh. For this guide v31.0.0-pre1 was used, which is the most recent Prerelease version. On the far right click the Download ZIP button. Unzip this to a folder of your choice.

Building CefSharp

Open the CefSharp3.sln file in Visual Studio.

  1. Right click the CefSharp.Wpf.Example project and click Set as Startup Project.
  2. Go to Tools->NuGet Package Manager ->Manage NuGet Packages for Solution... and you should see a Restore button in the upper right. The solution uses NuGet packages to grab the native CEF DLLs and other dependencies. Usually the Restore happens automatically when you first build, but it doesn't hurt to be sure.
  3. Build the solution(usually F6) and ensure it builds successfully.

If you have issues with this step, refer to Building CefSharp

Running the Example

You can run the example from Visual Studio by hitting F5, as well as browsing to the bin diroectory of the project: CefSharp.Wpf.Example/bin/x86/Debug/CefSharp.Wpf.Example.exe

If successful, you should see a simple web browser application with two tabs: one with a Getting Started page and the other with the Google homepage.

If it fails, see Copying Dependencies section below, and also review Building CefSharp for anything that might affect you.

NuGet Packages

Now that you hopefully have gotten the examples to run, you probably don't want to build CefSharp from source in your own project. As mentioned before, CefSharp binaries are available via NuGet.

You are more likely to encounter missing dependency issues in your own project, and may need to copy them manually or add them to the project with Copy Always set. Referencing one of the NuGet packages such as CefSharp.Wpf will also automatically pull in the NuGet packages for the native dependencies. So you should be able to find all required files under the packages folder of your own project referencing a CefSharp package, and copy them to your bin directory.

Copying Dependencies

If the example crashes with FileNotFound exceptions regarding loading DLLs you may have some missing native CEF files. All CEF native dependencies should be copied to the output directory automatically during the build, but just in case let's cover what is needed.

Depending on the failure, there is sometimes a debug.log file created in the Debug bin directory that might give a hint about what the problem.

The following files, in addition to the usual .NET project files, should be present in the bin directory. They should live side-by-side in the same directory as the CefSharp.Wpf.Example.exe file, except for en-US.pak which is in a locales subdirectory:

  • cef.pak
  • devtools_resources.pak
  • icudt.dat
  • libcef.dll
  • /locales/en-US.pak

If any are missing, they can be usually be found under

  • solutionfolder\packages\cef.redist.3.1650.1562-pre0\CEF\
  • \x86*
  • \locales\en-US.pak
  • \cef.pak
  • \devtools_resources.pak

If these files under the packages folder are missing, then it is probably an issue with retrieving the nuget packages. Ensure you followed the instructions for Restoring the packages.

Additional files beyond the above listing may be required based on the features in the HTML pages you are rendering. These can also usually be found within the NuGet packages. See the Windows section of the native CEF's project page GeneralUsage for a listing of other DLLs and the functionality they provide(such as supporting video elements).