Getting Started CefGlue Winapi (.NET Core) - RupertAvery/Chromely GitHub Wiki

Creating .NET Core CefGlue Applications (64-bit)

Note: Visual Studio 2017 is preferred. Recent older versions like 2015 should work too but not supported.

  1. Create .NET Core Console Application
  2. Ensure that the build platform target is x64.
  3. From project property, change "Console Application"" to "Windows Application" [Project -> Properties -> Application -> Output type: "Windows Application"].
  4. To ensure that all required dlls are built in the right bin folder, add the following to the project file:
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  1. Add Chromely.CefGlue.Winapi from Nuget-prelease. (A warning may show, if this happens unload the project and reload.)
  • Chromely.CefGlue.Winapi has following dependencies and should be verified
    • Winapi from Nuget. (Ensure minimum of 4.0 version is installed that was released for .NET Standard.)
    • Chromely.Core from Nuget
  1. After adding the dll references, a warning may show, if this happens unload the project and reload.
  2. Add the following code snippet to the Main function in Program.cs.

Notes on Upgrade to CefGlue version 70 and CefSharp version 71 (Chromely v4) - Please see.

    class Program
    {
        static int Main(string[] args)
        {
            string startUrl = "https://www.google.com/";

            var config = ChromelyConfiguration
                             .Create()
                             .WithHostMode(WindowState.Normal, true)
                             .WithHostTitle("chromely")
                             .WithHostIconFile("chromely.ico")
                             .WithAppArgs(args)
                             .WithHostSize(1000, 600)

                              // .NET Core may not run in debug mode without publishing to exe
                              // To overcome that, a subprocess need to be set.
                              //.WithCustomSetting(CefSettingKeys.BrowserSubprocessPath, path_to_subprocess)
                              .WithStartUrl(startUrl);

          using (var window = ChromelyWindow.Create(config))
          {
            return window.Run(args);
          }
        }
    }
- Creates Chromely window of size 1000 x 600 pixels.
- Sets the window title to "chromely"
- Sets start url to "https://www.google.com/"
- Centers the window 
  1. Build the project. From version 66 and above, building the project also downloads the required CEF binaries.

  2. From Chromely.CefGlue.Winapi version 66 and upward, CEF binaries download is not required anymore. Only valid for nuget packages

    • Note: .NET Core sometimes gives a "An attempt was made to load a program with an incorrect format.". This is a bug due to .NET and .NET Core build processes not picking the appropriate CPU. If this happens a manual CEF binaries download is required.

    • If CEF binaries files/folders download is required, please try either of these two options-

  3. Run the built dll file with F5 or "dotnet demo.dll"on cmd.

  4. If successful the following will be shown:

Puplishing - Creating self-contained app

  1. Below must be commented out or removed:Note that this only applies to v66 and lower
   // The single process should only be used for debugging purpose.
   // For production, this should not be needed when the app is published 

   // Alternate approach for multi-process, is to add a subprocess application
   //.WithCustomSetting(CefSettingKeys.BrowserSubprocessPath, path_to_subprocess)
   .WithCustomSetting(CefSettingKeys.SingleProcess, true)
  1. Add platform RuntimeIdentifiers flags in the project file.
  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>netcoreapp2.0</TargetFramework>
    <RuntimeIdentifiers>win10-x64;ubuntu.16.10-x64</RuntimeIdentifiers>
    <Platforms>x64</Platforms>
  </PropertyGroup>
  1. Look for online help to create .NET Core self-contained apps if needed. An example can be found here.
  2. See demo project here.

How to Hide .NET Core Console

Launching the app using published self-contained exe will also launch the console window. One way to stop this is to use EDITBIN.EXE tool.

Using

editbin.exe /subsystem:windows cefglue_winapi_netcoredemo.exe

You can see more info on this, in the following:

⚠️ **GitHub.com Fallback** ⚠️