From 9632e10c14224c9c0661c1f3d2d6aeaddb1438f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Konstantin=20Prei=C3=9Fer?= Date: Tue, 10 Sep 2019 10:20:34 +0200 Subject: [PATCH] Add .NET Core 3.0 WinForms/WPF/OffScreen examples (#57) * Add minimal WinForms and WPF examples using .NET Core 3.0 projects, reusing the existing code files. Issue cefsharp/CefSharp#2796 * Follow-Up: Add a minimal OffScreen example using a .NET Core 3.0 project. * Upgrade to 75.1.142. * Update README.md to mention .NET Core support. * Fix typo. * Add comment about UseShellExecute. --- ...rp.MinimalExample.OffScreen.netcore.csproj | 30 +++++++++++ CefSharp.MinimalExample.OffScreen/Program.cs | 6 ++- .../BrowserForm.cs | 16 +++++- ...arp.MinimalExample.WinForms.netcore.csproj | 30 +++++++++++ ...CefSharp.MinimalExample.Wpf.netcore.csproj | 32 ++++++++++++ CefSharp.MinimalExample.netcore.sln | 51 +++++++++++++++++++ README.md | 17 +++++-- 7 files changed, 176 insertions(+), 6 deletions(-) create mode 100644 CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.netcore.csproj create mode 100644 CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.netcore.csproj create mode 100644 CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.netcore.csproj create mode 100644 CefSharp.MinimalExample.netcore.sln diff --git a/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.netcore.csproj b/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.netcore.csproj new file mode 100644 index 0000000..139f013 --- /dev/null +++ b/CefSharp.MinimalExample.OffScreen/CefSharp.MinimalExample.OffScreen.netcore.csproj @@ -0,0 +1,30 @@ + + + Exe + netcoreapp3.0 + true + CefSharp.MinimalExample.OffScreen + app.manifest + false + x86;x64 + + + + + + + + + + true + + + true + + + true + + + diff --git a/CefSharp.MinimalExample.OffScreen/Program.cs b/CefSharp.MinimalExample.OffScreen/Program.cs index 855723c..7710f98 100644 --- a/CefSharp.MinimalExample.OffScreen/Program.cs +++ b/CefSharp.MinimalExample.OffScreen/Program.cs @@ -88,7 +88,11 @@ namespace CefSharp.MinimalExample.OffScreen Console.WriteLine("Screenshot saved. Launching your default image viewer..."); // Tell Windows to launch the saved image. - Process.Start(screenshotPath); + Process.Start(new ProcessStartInfo(screenshotPath) + { + // UseShellExecute is false by default on .NET Core. + UseShellExecute = true + }); Console.WriteLine("Image viewer launched. Press any key to exit."); }, TaskScheduler.Default); diff --git a/CefSharp.MinimalExample.WinForms/BrowserForm.cs b/CefSharp.MinimalExample.WinForms/BrowserForm.cs index 63ae770..8e041f8 100644 --- a/CefSharp.MinimalExample.WinForms/BrowserForm.cs +++ b/CefSharp.MinimalExample.WinForms/BrowserForm.cs @@ -33,9 +33,21 @@ namespace CefSharp.MinimalExample.WinForms browser.TitleChanged += OnBrowserTitleChanged; browser.AddressChanged += OnBrowserAddressChanged; + var version = string.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}", + Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion); + +#if NETCOREAPP + // .NET Core + var environment = string.Format("Environment: {0}, Runtime: {1}", + System.Runtime.InteropServices.RuntimeInformation.ProcessArchitecture.ToString().ToLowerInvariant(), + System.Runtime.InteropServices.RuntimeInformation.FrameworkDescription); +#else + // .NET Framework var bitness = Environment.Is64BitProcess ? "x64" : "x86"; - var version = String.Format("Chromium: {0}, CEF: {1}, CefSharp: {2}, Environment: {3}", Cef.ChromiumVersion, Cef.CefVersion, Cef.CefSharpVersion, bitness); - DisplayOutput(version); + var environment = String.Format("Environment: {0}", bitness); +#endif + + DisplayOutput(string.Format("{0}, {1}", version, environment)); } private void OnIsBrowserInitializedChanged(object sender, EventArgs e) diff --git a/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.netcore.csproj b/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.netcore.csproj new file mode 100644 index 0000000..be0af01 --- /dev/null +++ b/CefSharp.MinimalExample.WinForms/CefSharp.MinimalExample.WinForms.netcore.csproj @@ -0,0 +1,30 @@ + + + WinExe + netcoreapp3.0 + true + CefSharp.MinimalExample.WinForms + app.manifest + false + x86;x64 + + + + + + + + + + true + + + true + + + true + + + diff --git a/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.netcore.csproj b/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.netcore.csproj new file mode 100644 index 0000000..2546316 --- /dev/null +++ b/CefSharp.MinimalExample.Wpf/CefSharp.MinimalExample.Wpf.netcore.csproj @@ -0,0 +1,32 @@ + + + WinExe + netcoreapp3.0 + true + CefSharp.MinimalExample.Wpf + chromium-256.ico + app.manifest + false + x86;x64 + + + + + + + + + + + true + + + true + + + true + + + \ No newline at end of file diff --git a/CefSharp.MinimalExample.netcore.sln b/CefSharp.MinimalExample.netcore.sln new file mode 100644 index 0000000..7a2a731 --- /dev/null +++ b/CefSharp.MinimalExample.netcore.sln @@ -0,0 +1,51 @@ + +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29230.61 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.MinimalExample.WinForms.netcore", "CefSharp.MinimalExample.WinForms\CefSharp.MinimalExample.WinForms.netcore.csproj", "{4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.MinimalExample.Wpf.netcore", "CefSharp.MinimalExample.Wpf\CefSharp.MinimalExample.Wpf.netcore.csproj", "{83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}" +EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "CefSharp.MinimalExample.OffScreen.netcore", "CefSharp.MinimalExample.OffScreen\CefSharp.MinimalExample.OffScreen.netcore.csproj", "{AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|x64 = Debug|x64 + Debug|x86 = Debug|x86 + Release|x64 = Release|x64 + Release|x86 = Release|x86 + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Debug|x64.ActiveCfg = Debug|x64 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Debug|x64.Build.0 = Debug|x64 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Debug|x86.ActiveCfg = Debug|x86 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Debug|x86.Build.0 = Debug|x86 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Release|x64.ActiveCfg = Release|x64 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Release|x64.Build.0 = Release|x64 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Release|x86.ActiveCfg = Release|x86 + {4E27910D-3B6C-41C1-84B4-A05C58EE8AE8}.Release|x86.Build.0 = Release|x86 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Debug|x64.ActiveCfg = Debug|x64 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Debug|x64.Build.0 = Debug|x64 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Debug|x86.ActiveCfg = Debug|x86 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Debug|x86.Build.0 = Debug|x86 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Release|x64.ActiveCfg = Release|x64 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Release|x64.Build.0 = Release|x64 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Release|x86.ActiveCfg = Release|x86 + {83E2C9C4-2967-4A49-8B2A-D31D33DCFB03}.Release|x86.Build.0 = Release|x86 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Debug|x64.ActiveCfg = Debug|x64 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Debug|x64.Build.0 = Debug|x64 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Debug|x86.ActiveCfg = Debug|x86 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Debug|x86.Build.0 = Debug|x86 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Release|x64.ActiveCfg = Release|x64 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Release|x64.Build.0 = Release|x64 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Release|x86.ActiveCfg = Release|x86 + {AB1B7B81-D472-43B2-AFE3-DE5D1B22B9CE}.Release|x86.Build.0 = Release|x86 + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {81E9E2D5-A36B-4EB6-82A4-BAE734AEB0CC} + EndGlobalSection +EndGlobal diff --git a/README.md b/README.md index b13a26b..8457ed3 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -CefSharp.MinimalExample -======================= +# CefSharp.MinimalExample -Minimal example of how the CefSharp library can be used using the official `Nuget` packages. +Minimal example of how the CefSharp library can be used using the official `Nuget` packages with .NET Framework +projects (`CefSharp.MinimalExample.sln`) and .NET Core projects (`CefSharp.MinimalExample.netcore.sln`). Includes examples for - WinForms @@ -10,3 +10,14 @@ Includes examples for For a more complete example of each project see the main `CefSharp` repository. + +## .NET Core support +As of version `75.1.142`, the CefSharp NuGet packages can be used with .NET Core 3.0 projects (as shown by the examples). However, the current versions have some limitations that you should be aware of: +- The target machine still needs to have .NET Framework 4.5.2 or higher installed, as the `CefSharp.BrowserSubprocess.exe` is still used. +- The project file needs to update the references of `CefSharp.WinForms`/`CefSharp.WPF`/`CefSharp.OffScreen`, as well as `CefSharp.Core` and `CefSharp` to use `true`, as otherwise the CoreCLR would not load these libraries as they would not be specified in the `.deps.json` file. +- When publishing a self-contained app using a runtime identifier `win-x64` or `win-x86`, you need to set the `Platform` property to `x64` or `x86`; as otherwise it would be `AnyCPU` and the check in the `.targets` file of the NuGet package would fail.
+ Example: + - x86: `dotnet publish -f netcoreapp3.0 -r win-x86 -p:Platform=x86` + - x64: `dotnet publish -f netcoreapp3.0 -r win-x64 -p:Platform=x64` + +It is possible to publish the application as single EXE file by adding `-p:PublishSingleFile=true`.