Skip to content
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

Move CefSharp Dependencies to Subfolder #601

Closed
bjarteskogoy opened this issue Nov 13, 2014 · 16 comments
Closed

Move CefSharp Dependencies to Subfolder #601

bjarteskogoy opened this issue Nov 13, 2014 · 16 comments
Milestone

Comments

@bjarteskogoy
Copy link

Is it possible to place libcef.dll in another folder than CefSharp.BrowserSubprocess.exe ?

@amaitland
Copy link
Member

You could try calling SetDllDirectory, you'd have to keep BrowserSubProcess in the same directory, as it wouldn't know where to search for libcef

http://msdn.microsoft.com/en-us/library/windows/desktop/ms686203%28v=vs.85%29.aspx

@amaitland
Copy link
Member

@bjarteskogoy Did you resolve this? Can we close this issue?

@amaitland
Copy link
Member

Adding this for my own reference, it maybe possible to use the <probing/> app config entry to move all of CefSharp to a sub folder.

https://msdn.microsoft.com/en-us/library/4191fzwb.aspx

@amaitland
Copy link
Member

Quick test and it appears that it works as advertised.

  • Update MinimalExample app to set BrowserSubprocessPath = @"cefsharp\CefSharp.BrowserSubprocess.exe"}
  • Edit app.config and add <probing privatePath="cefsharp"/> as outlined in msdn article
  • Copy all CefSharp dll's in cefsharp subfolder (do this second so the msbuild task doesn't copy the dll's)
  • Run app.

@amaitland amaitland changed the title libcef Move CefSharp Dependencies to Subfolder Apr 15, 2015
@amaitland
Copy link
Member

You'll also have to set the CefSettings.BrowserSubprocessPath property, currently defaults to being the executing path.

https://github.com/cefsharp/CefSharp/blob/cefsharp/47/CefSharp.Core/CefSettings.h#L29

@amaitland
Copy link
Member

Example using new CefLibraryHandler class, dlls in this example have been moved to D:\projects\CefSharp.MinimalExample\libs\ and the cef.redist.x86.targets, cef.redist.x64.targets and CefSharp.Common.targets files removed from the csproj, they will be re-added next time you upgrade the Nuget packages. This is a rough example, only attempt if your comfortable supporting yourself. Make sure you read the comments inline below.

// Copyright © 2010-2015 The CefSharp Authors. All rights reserved.
//
// Use of this source code is governed by a BSD-style license that can be found in the LICENSE file.

using System;
using System.Runtime.CompilerServices;
using System.Windows.Forms;

namespace CefSharp.MinimalExample.WinForms
{
    public class Program
    {
        [STAThread]
        public static void Main()
        {
            var libraryLoader = new CefLibraryHandle(@"D:\projects\CefSharp.MinimalExample\libs\libcef.dll");

            var isValid = libraryLoader.IsInvalid;

            //Calls to CEF cannot be made directly in this method, doing so would
            //attempt to load `CefSharp.Core` which requires `libcef.dll` which
            //we are now dynamically loading from our own folder. 
            LoadForm();

            libraryLoader.Dispose();
        }

        //Must make this this method isn't inlined otherwise it will
        // dynamically load CefSharp.Core
        [MethodImpl(MethodImplOptions.NoInlining)]
        private static void LoadForm()
        {
            var settings = new CefSettings();
            //Must specify these three paths
            settings.BrowserSubprocessPath = @"D:\projects\CefSharp.MinimalExample\libs\CefSharp.BrowserSubprocess.exe";
            settings.LocalesDirPath = @"D:\projects\CefSharp.MinimalExample\libs\locales";
            settings.ResourcesDirPath = @"D:\projects\CefSharp.MinimalExample\libs";

            //Must set performDependencyCheck: false 
            Cef.Initialize(settings, shutdownOnProcessExit: false, performDependencyCheck: false);

            var browser = new BrowserForm();
            Application.Run(browser);
        }
    }
}

@amaitland amaitland added this to the 51.0.0 milestone Jun 13, 2016
@amaitland
Copy link
Member

You can copy paste CefLibraryHandler into your project if you require this in older versions, it's a purely managed implementation.

@amaitland
Copy link
Member

With #1714 it should also be possible to modify the example Assembly Resolver to load the resources from any folder you like. Probably slightly easier than the method listed above.

@BlackBooth
Copy link

BlackBooth commented Jul 6, 2016

Hi, I created a gist, where I used the AssemblyResolver method mentioned above to move the cefsharp files to a subfolder. You can find it here. When you compile it in debug mode nothing happens, but when you use release mode the AssemblyResolver does its magic and redirects all cefsharp dll requests to the designated subfolder. Right now I manually move the cefsharp files to the subfolder. Maybe there is a better solution, to do this automatically when compiling in release mode.

@amaitland
Copy link
Member

I've never seen a problem with Debug mode, so maybe that's specific to your environment? Regardless, going forward the recommended approach would be to use #1714

@BlackBooth
Copy link

It does nothing on debug because I want it to ;)

#if !DEBUG
            AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
#endif

It uses the approach of #1714

@amaitland
Copy link
Member

It does nothing on debug because I want it to ;)

I have no idea what the purpose of your comments is then?

@BlackBooth
Copy link

Sorry, I had my mind on another problem, which turned out not to be one. So i changed my gist to be more flexible.

  • Link to Gist
  • Compile mode doesn't matter (release / debug)
  • When you run your program, the main assembly looks for the chefsharp files in the same directory like the main executable and loads them
  • If it can't find them there the assembly resolver gets to work and tries to load the assembly from the designated cefSubFolder

So if you like a clean folder structure you move all cefsharp files to the cefsharp subfolder

@amaitland
Copy link
Member

Sorry, I had my mind on another problem, which turned out not to be one. So i changed my gist to be more flexible.

@BlackBooth Ok, thanks for the example 👍 In general I'd recommend removing all unnecessary pieces of code when providing an example, like javascript binding, browser settings`, form resizing. Inline comments would be worth adding as your providing a reference that others will use.

@XanderLuciano
Copy link

For future reference, I just followed your steps and did a quick tutorial on StackOverflow to (hopefully) make the steps a little easier to follow.

http://stackoverflow.com/questions/39400139/how-to-move-cefsharp-dependencies-and-files-to-subdirectory/39400140#39400140

@amaitland
Copy link
Member

For future reference, I just followed your steps and did a quick tutorial on StackOverflow to (hopefully) make the steps a little easier to follow.

@XanderLuciano Your example is unnessicarily complex, you don't need a probingPath, and an assembly resolver. Just use something like https://gist.github.com/BlackBooth/19ce027c4f68c1eb4fc1144988ca6662

When 53.0.0 is released you'll be able to specify where the libs are copied as well, aka #1753

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants