发布无法加载文件或程序集 CefSharp.Core.dll

Publish Could not load file or assembly CefSharp.Core.dll

我在我的 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.

我设法将提到的所有需要​​的文件收集到一个文件夹中 Here 并将其命名为 dll 然后我将其放入 packages 文件夹中

现在在 .csproj 中,在 </Project> 之前我添加了

  <ItemGroup>
    <Content Include="$(SolutionDir)packages\dll\**\*.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>

发布后应用磨损,已解决

我来晚了一点,但要在这里补充一点,我使用以下方法解决将 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"

Post-构建:

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>