-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Publish self-contained .NET 5 application #3407
Comments
Does it work if you publish leaving the The For this use case I expect you'll need to self host the Whilst I understand this is a little harder for There are some linker errors trying to compile the |
I will test.
Great! Then that is an acceptable solution for me. Thank you :) |
I also ran into an issue publishing with self-contained selected using CefSharp.Winforms.NETCore 87.1.132. I first tried publishing with my own application with target framework of net5.0-windows. When running my published executable, the window opens, but the page does not load and my mouse pointer constantly toggles the loading icon on/off. I then tried publishing the minimal example that targets netcoreapp3.1 with self-contained selected. The same thing happens when I run the published executable. The window opens, but the page doesn't load, and the mouse constantly toggles loading icon on/off. Screenshot attached of what loads when running the executable. When I use "framework-dependent" instead of "self-contained", the published executable works perfectly. I checked out the potential fix you mentioned for self hosting the BrowserSubprocess. I added the following code to my Main method and publishing with self-contained on .NET 5 for WinForms seems to work:
|
This may actually have nothing to do with it at all. The For publishing self contained and single file applications self hosting the For [STAThread]
public static int Main(string[] args)
{
//To support High DPI this must be before CefSharp.BrowserSubprocess.SelfHost.Main so the BrowserSubprocess is DPI Aware
Cef.EnableHighDPISupport();
var exitCode = CefSharp.BrowserSubprocess.SelfHost.Main(args);
if (exitCode >= 0)
{
return exitCode;
}
var settings = new CefSettings()
{
//By default CefSharp will use an in-memory cache, you need to specify a Cache Folder to persist data
CachePath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "CefSharp\\Cache"),
BrowserSubprocessPath = System.Diagnostics.Process.GetCurrentProcess().MainModule.FileName
};
//Perform dependency check to make sure all relevant resources are in our output directory.
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
var browser = new BrowserForm();
Application.Run(browser);
return 0;
} See https://github.com/cefsharp/CefSharp/blob/cefsharp/87/CefSharp.Core/BrowserSubprocess/SelfHost.cs#L26 for additional details. Target machines still require For future reference |
…bprocess.runtimeconfig.json For SelfContained and PublishSingleFile we remove the CefSharp.BrowserSubprocess.runtimeconfig.json file so the BrowserSubprocess runs using the packages .net runtime Issue #3407
…bprocess.runtimeconfig.json For SelfContained and PublishSingleFile we remove the CefSharp.BrowserSubprocess.runtimeconfig.json file so the BrowserSubprocess runs using the packages .net runtime Issue #3407
For SelfContained builds deleting the
As .Net Core 3.1
.Net 5.0
Removing the file from the Important
Using
Disclaimer
|
This should now work with the SelfContained = true and SingleFile = false with .Net 5.0 SelfContained = true and SingleFile = true under .Net 5.0 the apphost has hostfxr.dll and hostpolicy.dll statically linked into the runtime exe. As the included runtime doesn't include the required dlls to run the Generating a
See https://github.com/dotnet/designs/blob/main/accepted/2020/single-file/design.md#host-builds Add the following to your project file (or set via command line when using dotnet publish) to see details of the files that are packed into the single file exe.
The |
- Use the main application exe as the BrowserSubprocess when self publishing a .Net 5.0 exe - Only the WPF and WinForms examples have been updated cefsharp/CefSharp#3407
The following should copy the <Import Project="$(DevEnvDir)..\..\VC\Auxiliary\Build\Microsoft.VCToolsVersion.default.props"/>
<Target Name="IncludeVisualCppInOutFolder" AfterTargets="ResolveReferences">
<PropertyGroup>
<_VCRedistLocation>$(DevEnvDir)..\..\VC\Redist\MSVC\$(VCToolsRedistVersion)\$(PlatformTarget)\Microsoft.VC142.CRT</_VCRedistLocation>
</PropertyGroup>
<Message Importance="high" Text="_VCRedistLocation = $(_VCRedistLocation)" />
<ItemGroup>
<ReferenceCopyLocalPaths Include="$(_VCRedistLocation)\**\*" />
</ItemGroup>
</Target> The latest |
* Upgrade to v88.2.40-pre WPF - Add https scheme to default URL to workaround upstream issue https://bitbucket.org/chromiumembedded/cef/issues/3079/cant-load-urls-without-scheme * Net Core - Add AnyCPU Platform to projects/solution * Net Core - Add RuntimeIdentifier based on PlatformTarget - Set RuntimeIdentifier based on PlatformTarget (PlatformTarget isn't set of AnyCPU) - Set SelfContained to false so as not to provide a Framework Dependant build (don't include the whole .net framework) * WPF/WinForms - Change CefSharpBuildAction to Content For testing of ClickOnce publish * Net 5.0 - Update to include PublishSingleFile settings - .Net 5.0 Publish Settings for PublishSingleFile https://docs.microsoft.com/en-us/dotnet/core/deploying/single-file Defaults differ compared to .Net Core 3.1 - Set RollForward to Major so runs on newer runtime version - Add net5.0-windows TargetFramework * .Net 5.0 - Publish Single Exe Example - Use the main application exe as the BrowserSubprocess when self publishing a .Net 5.0 exe - Only the WPF and WinForms examples have been updated cefsharp/CefSharp#3407 * Upgrade to 88.2.90
The CefSharp.MinimalExample has been updated to include an example of self hosting the
Changes were added in commit cefsharp/CefSharp.MinimalExample@9da6406 which should provide a fairly detailed example for those of you who require one. Researching/Debugging/Documenting takes a significant amount of my time. If you are using |
@amaitland Thank you for solving this! 😃I have enabled github sponsorship from our company. |
@peters Thank you so much!! Please let me know if you have any problems. |
First of all, thank you for the great effort of enabling .NET core support. I tried updating our kiosk software from
net48
tonet5.0-windows
. Using the latest pre-release this was quite easy. But when I published the application using a self-contained runtime it would run but was unable to render the web browser control. After a bit of experimenting I noticed that if I copy allCefSharp
assets to a separate directory and changedCefSettings.BrowserSubprocessPath
property toPath.Combine(currentDirectory, "cefsharp", "CefSharp.BrowserSubprocess.exe")
and not deleting the aforementioned assets from the publish directory everything works as it should.What version of the product are you using?
What architecture x86 or x64?
On what operating system?
Are you using
WinForms
,WPF
orOffScreen
?What steps will reproduce the problem?
git clone https://github.com/cefsharp/CefSharp.MinimalExample.git
CefSharp.MinimalExample.Wpf.csproj
target framework tonet5.0-windows
CefSharp.Wpf.NETCore
package reference to88.2.40-pre
cd CefSharp.MinimalExample
dotnet publish .\CefSharp.MinimalExample.netcore.sln -c Release --runtime win-x64 --self-contained
.\CefSharp.MinimalExample.Wpf\bin.netcore\x64\Release\net5.0-windows\win-x64\publish\CefSharp.MinimalExample.Wpf.netcore.exe
What is the expected output? What do you see instead?
The text was updated successfully, but these errors were encountered: