Repository navigation
WinForms/WPF does not work when packaged as WAP (Desktop Bridge) project. #2642
Description
Activity
What version are you using? Nuget? CI Nuget? build from a branch? If so which branch? Please include the exact version number you are using (no ambiguous statements like Latest from Nuget) e.g. 57.0.0 or 63.0.0-pre01
As per https://github.com/cefsharp/CefSharp/blob/cefsharp/71/ISSUE_TEMPLATE.md#bug-report please specify the exact version you are using, Latest NuGet package is relative and will be inaccurate as soon as the next version is released.
- and also uses AnyCPU architecture, as described in Feature Request - Add AnyCPU Support #1714.
There are three options listed for
AnyCPU, please specify which one you are using.I think that issue comes from the fact that *.targets and *.props files which ship with NuGet package add a backslash after $(CefSharpTargetDir), as seen here:
The
<None/>entries inCefSharp.Common.propsshouldn't actually be there, thanks for highlighting that. They have been removed in 3c650a0I didn't test this further, but I believe that fix would be to
a) Remove backslash between
$(CefSharpTargetDir)and%(RecursiveDir)in all<Link>attributes.
b) Add MSBuild code to ensure that$(CefSharpTargetDir)is always terminated with a backslash (if specified).You can easily test this
- Actually specify a value for
$(CefSharpTargetDir)and modify theAnyCPUoption you have chosen (I have no idea which one you chose, so I cannot provide any specifics). This is pretty trivial. - Manually edit your local cached copy of
.targetsfiles (unload/reload the solution inVSof course).
- changed the title
[-]WinForms CefSharp app does not work when packages as WAP project.[/-][+]WinForms does not work when packaged as WAP (Desktop Bridge) project.[/+]on Feb 7, 2019 I just wanted to chime in and say that I found a bit of a hacky workaround yesterday. The issue isn't winforms specific. It fails with wpf and will probably fail with offscreen as well.
Following your advice, I set CefSharpTargetDir using this line in the .csproj for the main application inside the PropertyGroup tag:
<CefSharpTargetDir` Condition=" '$(CefSharpTargetDir)' == '' ">.</CefSharpTargetDir>
Using . was the first value I found that worked for both the main application and the WAP project.
I set the MSBuild log to Detailed and where it used to fail, it shows this now:
5> Task "Message"
5> Payload: (packagename).\cef.pak from C:\Users\Jeff.nuget\packages\cef.redist.x86\73.1.13\CEF\cef.pakI'm not that well versed with MSBuild wizardry, so I'm going to just use what I have that works at this point, but maybe this will be the spark for someone who is well versed in that area to come up with a more elegant solution and bring this across the finish line.
Hope this helps.
jeffxpx, I can confirm your solution/hack is working. I had exactly the same problem as srdjanjovcic, but I use the "Windows Application Packaging Project" for creating an appxbundle.
I can also confirm I got a desktop bridge sample working using the info found here, thank you!
Before doing the following I got an error saying, when running the desktop bridge project (running the regular WinForms project would work):
Could not load file or assembly 'CefSharp.WinForms, Version=75.1.141.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.But I have also seen the error referring to
cef.pakabove. Not sure what the reason for that was, but it had the same solution, setting$(CefSharpTargetDir).What I did then (using the instructions here) was:
- Cloned out:
https://github.com/cefsharp/CefSharp.MinimalExample.git - Removed the WPF and OffScreen projects (I wanted to use WinForms for best performance)
- Used
x64(the default for the Minimal example) - Edited the
CefSharp.MinimalExample.WinForms.csprojfile by adding (to the bottom of the first<PropertyGroup>:
<CefSharpTargetDir Condition=" '$(CefSharpTargetDir)' == '' ">.</CefSharpTargetDir>
Not sure what the best solution regarding x86 vs x64 would be when submitting to the store, maybe you can submit multiple versions?
Many thanks @jeffxpx @srdjanjovcic @amaitland !
- Cloned out:
@johot, we are a bit off of the original question, but you can submit multiple versions. The installer detects which processor user has and install the correct version.
@johot, we are a bit off of the original question, but you can submit multiple versions. The installer detects which processor user has and install the correct version.
You are correct sorry about that :) I'm just very happy a solution has been found. Will there be a way to fix this for all users you think? I would have been pretty lost without finding this issue :)
- changed the title
[-]WinForms does not work when packaged as WAP (Desktop Bridge) project.[/-][+]WinForms/WPF does not work when packaged as WAP (Desktop Bridge) project.[/+]on Sep 29, 2019 Defaulting
CefSharpTargetDirto.seems like the easiest option, so we'll go with that for now.- added a commit that references this issue
on Nov 1, 2019
What version of the product are you using? Latest NuGet package.
What architecture x86 or x64? AnyCPU
On what operating system? Win10
Are you using
WinForms,WPForOffScreen? WinForms, packaged as WAP (see Package a desktop application by using Visual Studio).What steps will reproduce the problem? Attempt to create a WAPPROJ to package WinForms app which uses CefSharp, and also uses AnyCPU architecture, as described in Feature Request - Add AnyCPU Support #1714.
I think that issue comes from the fact that *.targets and *.props files which ship with NuGet package add a backslash after $(CefSharpTargetDir), as seen here:
When
$(CefSharpTargetDir)is not set (as it is a default),<Link>metadata ends up starting with\, which causes those files to be included into root folder of APPX package, and application cannot find them.I didn't test this further, but I believe that fix would be to
a) Remove backslash between
$(CefSharpTargetDir)and%(RecursiveDir)in all<Link>attributes.b) Add MSBuild code to ensure that
$(CefSharpTargetDir)is always terminated with a backslash (if specified).