-
-
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
Configure directory where msbuild will copy CefSharp files #1753
Conversation
@intrueder Thanks for the contribution! I'm currently working on other things at the moment, will probably take at least a few weeks before this is reviewed. |
@intrueder I've had a quick look over your |
This feature should be used in conjunction with AnyCPU support ( #1714 ) code sample. |
It's not limited to
I have no plans to document
Please write some documentation and I'll consider it for inclusion in #1714 |
Complete code sample. (I've modified original sample a bit, because .csproj <PropertyGroup>
<CefSharpTargetDir>C:\MyProjectOutDir\Cef</CefSharpTargetDir>
</PropertyGroup> .cs public partial class App : Application
{
public App()
{
//Add Custom assembly resolver
AppDomain.CurrentDomain.AssemblyResolve += Resolver;
// Any CefSharp references have to be in another method with NonInlining
// attribute so the assembly rolver has time to do it's thing.
InitializeCefSharp();
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp()
{
var settings = new CefSettings();
settings.EnableInternalPdfViewerOffScreen();
// Set BrowserSubProcessPath based on app bitness at runtime
settings.BrowserSubprocessPath = GetArchitectureSpecificPath("CefSharp.BrowserSubprocess.exe");
// Make sure you set performDependencyCheck false
Cef.Initialize(settings, shutdownOnProcessExit: false, performDependencyCheck: false);
}
// Will attempt to load missing assembly from either x86 or x64 subdir
// Required by CefSharp to load the unmanaged dependencies when running using AnyCPU
private static Assembly Resolver(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp"))
{
string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
string archSpecificPath = GetArchitectureSpecificPath(assemblyName);
if (File.Exists(archSpecificPath))
{
return Assembly.LoadFile(archSpecificPath);
}
}
return null;
}
private static string GetAssemblyDirectory()
{
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
}
private static string GetArchitectureSpecificPath(string fileName)
{
// subfolder is the same as $(CefSharpTargetDir) points to
string cefSubfolder = "Cef";
return Path.Combine(GetAssemblyDirectory(), cefSubfolder, Environment.Is64BitProcess ? "x64" : "x86", fileName);
}
} |
What problems are you seeing using |
This will likely be included as part of |
It is probably a special case..
and now, to avoid putting CefSharp files directly into C:\ProgramFiles\MyApp\Libs, I want to put them into subfolder. ApplicationBase points to MyApplication.exe path, i.e. C:\ProgramFiles\MyApp. |
i use CefSharp to create a wpf dialog to open a url ,and this dialog is embedded in excel. our product need call excelAddIn.dll and work on anyCPU platform . so i download the cef demo project from https://github.com/cefsharp/CefSharp.MinimalExample/tree/demo/anycpu .Now i encountered a problem that i just replace the url in MainWindow.xaml with my URL, and it works well, but after i finished all coding and dependency related according to the demo project , our project still can't work and throw a exception (An unhandled exception of type 'System.IO.FileNotFoundException' occurred in Unknown Module. |
During build process msbuild copies CefSharp files to
$(TargetDir)
Sometimes it is not suitable, and instead of override
$(TargetDir)
globally another property has been introduced. It's name is$(CefSharpTargetDir)
It is possible to override this property in
csproj
fileIf this property should depend on
$(TargetDir)
don't forget to override property after importingMicrosoft.CSharp.targets
($(TargetDir)
is defined there)Also,
$(TargetDir)
is used by default if$(CefSharpTargetDir)
was not specified incsproj
file