我在C#Windows窗体应用程序中使用CefSharp,当我从Visual Studio中运行它时,它运行良好,但是当我使用FTP帐户作为发布文件夹并使用url作为安装文件夹url进行发布
但是出现以下错误
我遵循了手册中的所有内容,并将所需的文件复制到bin文件夹中 (CefSharp.BrowserSubprocess.Core.dll,CefSharp.BrowserSubprocess.exe,CefSharp.Core.dll,CefSharp.dll,CefSharp.WinForms.dll,icudtl.dat,libcef.dll)
不幸的是,什么都不起作用,问题出在哪里?
See the end of this message for details on invoking
just-in-time (JIT) debugging instead of this dialog box.
************** Exception Text **************
System.IO.FileNotFoundException: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.
File name: 'CefSharp.Core.dll'
at mibrsdmapp.webBrowserForm.InitializeChromium()
at mibrsdmapp.webBrowserForm..ctor()
at mibrsdmapp.MeetingManager.btnCreate_Click(Object sender, EventArgs e)
at System.Windows.Forms.Control.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnClick(EventArgs e)
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
************** Loaded Assemblies **************
mscorlib
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4180.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/Windows/Microsoft.NET/Framework/v4.0.30319/mscorlib.dll
----------------------------------------
System
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4001.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System/v4.0_4.0.0.0__b77a5c561934e089/System.dll
----------------------------------------
mibrsdmapp
Assembly Version: 1.0.0.0
Win32 Version: 1.0.0.0
CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/mibrsdmapp.exe
----------------------------------------
System.Windows.Forms
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4150.0 built by: NET48REL1LAST_C
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Windows.Forms/v4.0_4.0.0.0__b77a5c561934e089/System.Windows.Forms.dll
----------------------------------------
System.Drawing
Assembly Version: 4.0.0.0
Win32 Version: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Drawing/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Drawing.dll
----------------------------------------
System.Configuration
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Configuration/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Configuration.dll
----------------------------------------
System.Core
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4180.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Core/v4.0_4.0.0.0__b77a5c561934e089/System.Core.dll
----------------------------------------
System.Xml
Assembly Version: 4.0.0.0
Win32 Version: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Xml/v4.0_4.0.0.0__b77a5c561934e089/System.Xml.dll
----------------------------------------
Newtonsoft.Json
Assembly Version: 12.0.0.0
Win32 Version: 12.0.3.23909
CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/Newtonsoft.Json.DLL
----------------------------------------
RestSharp
Assembly Version: 106.11.4.0
Win32 Version: 106.11.4
CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/RestSharp.DLL
----------------------------------------
System.Runtime.Serialization
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4180.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Runtime.Serialization/v4.0_4.0.0.0__b77a5c561934e089/System.Runtime.Serialization.dll
----------------------------------------
System.Numerics
Assembly Version: 4.0.0.0
Win32 Version: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Numerics/v4.0_4.0.0.0__b77a5c561934e089/System.Numerics.dll
----------------------------------------
System.Data
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4190.0 built by: NET48REL1LAST_B
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Data/v4.0_4.0.0.0__b77a5c561934e089/System.Data.dll
----------------------------------------
System.Web
Assembly Version: 4.0.0.0
Win32 Version: 4.8.4075.0 built by: NET48REL1LAST
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_32/System.Web/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Web.dll
----------------------------------------
System.Deployment
Assembly Version: 4.0.0.0
Win32 Version: 4.8.3752.0 built by: NET48REL1
CodeBase: file:///C:/WINDOWS/Microsoft.Net/assembly/GAC_MSIL/System.Deployment/v4.0_4.0.0.0__b03f5f7f11d50a3a/System.Deployment.dll
----------------------------------------
CefSharp.WinForms
Assembly Version: 83.4.20.0
Win32 Version: 83.4.20.0
CodeBase: file:///C:/Users/mhdiyad.bacdounes/AppData/Local/Apps/2.0/6ZYM7JQE.BG4/0Y7EKHZ7.LBH/mibr..tion_5015be9c01ee8c6d_0001.0000_80ee611c63296f33/CefSharp.WinForms.DLL
----------------------------------------
************** JIT Debugging **************
To enable just-in-time (JIT) debugging, the .config file for this
application or computer (machine.config) must have the
jitDebugging value set in the system.windows.forms section.
The application must also be compiled with debugging
enabled.
For example:
<configuration>
<system.windows.forms jitDebugging="true" />
</configuration>
When JIT debugging is enabled, any unhandled exception
will be sent to the JIT debugger registered on the computer
rather than be handled by this dialog box.
答案 0 :(得分:0)
我设法将Here中提到的所有需要的文件收集到一个文件夹中,并将其命名为dll,然后将其放入程序包文件夹中
现在在.csproj中,在我添加的</Project>
之前
<ItemGroup>
<Content Include="$(SolutionDir)packages\dll\**\*.*">
<Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
<Visible>false</Visible>
</Content>
</ItemGroup>
发布后应用程序很麻烦并且已解决
答案 1 :(得分:0)
我来晚了一点,但是要补充一点,我使用以下内容作为将CEFSharp文件移动到子文件夹中的问题的解决方案。 (贷记https://gist.github.com/BlackBooth/19ce027c4f68c1eb4fc1144988ca6662)
using CefSharp;
using System;
using System.IO;
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Windows.Forms;
namespace TestApp
{
internal static class Program
{
// The subfolder, where the cefsharp files will be moved to
private static string cefSubFolder = "CEFSharp";
// If the assembly resolver loads cefsharp from another folder, set this to true
private static bool resolved = true;
[STAThread]
private static void Main()
{
AppDomain.CurrentDomain.AssemblyResolve += CurrentDomain_AssemblyResolve;
InitializeCefSharp();
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm());
}
[MethodImpl(MethodImplOptions.NoInlining)]
private static void InitializeCefSharp()
{
var settings = new CefSettings();
// Set BrowserSubProcessPath when cefsharp moved to the subfolder
if (resolved)
settings.BrowserSubprocessPath = Path.Combine(Application.StartupPath, cefSubFolder, "CefSharp.BrowserSubprocess.exe");
// Make sure you set performDependencyCheck false
Cef.Initialize(settings, shutdownOnProcessExit: true, performDependencyCheck: false);
}
/// <summary>
/// Will attempt to load missing assemblys from subfolder
/// </summary>
private static Assembly CurrentDomain_AssemblyResolve(object sender, ResolveEventArgs args)
{
if (args.Name.StartsWith("CefSharp"))
{
resolved = true; // Set to true, so BrowserSubprocessPath will be set
string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
string subfolderPath = Path.Combine(Application.StartupPath, cefSubFolder, assemblyName);
return File.Exists(subfolderPath) ? Assembly.LoadFile(subfolderPath) : null;
}
return null;
}
}
}
然后在Visual Studio中使用以下构建事件。
预构建:
RD /S /Q "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp"
构建后:
dir /b /a-d "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\"|findstr /b "$(TargetName)" >"%temp%\searchfiles.tmp"
mkdir CEFSharp
xcopy "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp" /exclude:%temp%\searchfiles.tmp /y
cd "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\"
attrib +r $(TargetName).*
del /q *
attrib -r $(TargetName).*
move "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\locales" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp"
move "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\swiftshader" "$(ProjectDir)bin\$(PlatformName)\$(ConfigurationName)\CEFSharp"
更好,因为@amaitland建议修改项目以在CefSharp目标之前包含CefSharpTargetDir,并且文件将作为构建的一部分复制到子文件夹中。参见:https://github.com/cefsharp/CefSharp/blob/cefsharp/83/NuGet/CefSharp.Common.targets#L12
<PropertyGroup>
<CefSharpTargetDir Condition=" '$(CefSharpTargetDir)' == '' ">CEFSharp</CefSharpTargetDir>
</PropertyGroup>