Skip to content

WinForms/WPF does not work when packaged as WAP (Desktop Bridge) project. #2642

Description

@srdjanjovcic

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:

	<None Include="@(CefSharpCommonBinaries64)">
          <Link>$(CefSharpTargetDir)\%(RecursiveDir)%(FileName)%(Extension)</Link>
          <CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
        </None>

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).

Activity

  1. deleted a comment from welcome on Feb 7, 2019
  2. amaitland commented on Feb 7, 2019

    @amaitland
    Member

    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.

    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 in CefSharp.Common.props shouldn't actually be there, thanks for highlighting that. They have been removed in 3c650a0

    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).

    You can easily test this

    • Actually specify a value for $(CefSharpTargetDir) and modify the AnyCPU option 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 .targets files (unload/reload the solution in VS of course).
  3. 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
  4. jeffxpx commented on May 8, 2019

    @jeffxpx

    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.pak

    I'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.

  5. Snorvarg commented on May 19, 2019

    @Snorvarg

    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.

  6. added this to the 77.0.0 milestone on Jul 26, 2019
  7. johot commented on Aug 27, 2019

    @johot

    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.pak above. 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.csproj file 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 !

  8. Snorvarg commented on Aug 27, 2019

    @Snorvarg

    @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.

  9. johot commented on Aug 27, 2019

    @johot

    @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 :)

  10. 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
  11. amaitland commented on Oct 1, 2019

    @amaitland
    Member

    Defaulting CefSharpTargetDir to . seems like the easiest option, so we'll go with that for now.

  12. added a commit that references this issue on Nov 1, 2019
    70bf190
  13. modified the milestones: 79.0.0, 75.1.143 on Nov 3, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions