具有CefSharp应用程序的C#Winform在发布版本上崩溃

时间:2019-01-20 15:15:28

标签: c# winforms chromium cefsharp

我使用C#项目创建一个Winform CefSharp应用程序。 该应用程序在调试模式下运行良好,但是当我尝试使用VS2013对其进行发布时,它在应用程序开始运行之前崩溃。

这是我的program.cs文件:

    [STAThread]
    static void Main()
    {
        AppDomain.CurrentDomain.AssemblyResolve += Resolver;

        LoadApp();
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    private static void LoadApp()
    {
        var settings = new CefSettings();

        settings.BrowserSubprocessPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                               Environment.Is64BitProcess ? "x64" : "x86",
                                               "CefSharp.BrowserSubprocess.exe");

        settings.CachePath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + @"\TelegramParser\CEF";
        settings.IgnoreCertificateErrors = true;
        settings.WindowlessRenderingEnabled = true;
        settings.SetOffScreenRenderingBestPerformanceArgs();

        Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);

        Application.Run(new Form1());
    }

    private static Assembly Resolver(object sender, ResolveEventArgs args)
    {
        if (args.Name.StartsWith("CefSharp"))
        {
            string assemblyName = args.Name.Split(new[] { ',' }, 2)[0] + ".dll";
            string archSpecificPath = Path.Combine(AppDomain.CurrentDomain.SetupInformation.ApplicationBase,
                                                   Environment.Is64BitProcess ? "x64" : "x86",
                                                   assemblyName);

            return File.Exists(archSpecificPath)
                       ? Assembly.LoadFile(archSpecificPath)
                       : null;
        }

        return null;
    }

当我检查publish文件夹时,我只会看到以下文件: enter image description here

CefSharp Wiki上我了解到有一些文件丢失。知道可能是什么问题吗?

我使用Visual Studio 2013运行和发布项目。 我正在使用Any CPU进行编译。

编辑

<ItemGroup>
<Content
Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\x86\**\*;$(SolutionDir)packages\cef.redist.x86.3.2526.1362\CEF\locales\**\*.pak">
  <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
  <Visible>false</Visible>
</Content>

  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\**\en-US.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x86.3.3497.1841\CEF\x86\**\*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\CefSharp.Common.69.0.0\CefSharp\x86\**\CefSharp.BrowserSubprocess.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>

  <ItemGroup>
    <Content
    Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\*" Exclude="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\x64\**\*;$(SolutionDir)packages\cef.redist.x86.3.2526.1362\CEF\locales\**\*.pak">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\en-GB.*;$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\**\en-US.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\cef.redist.x64.3.3497.1841\CEF\x64\**\*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>
  <ItemGroup>
    <Content Include="$(SolutionDir)packages\CefSharp.Common.69.0.0\CefSharp\x64\**\CefSharp.BrowserSubprocess.*">
      <Link>%(RecursiveDir)%(Filename)%(Extension)</Link>
      <Visible>false</Visible>
    </Content>
  </ItemGroup>

我添加了此内容,现在应用程序因以下错误而崩溃:

An unhandled exception of type 'System.IO.FileNotFoundException' occurred in App.exe

Additional information: Could not load file or assembly 'CefSharp.Core.dll' or one of its dependencies. The specified module could not be found.

1 个答案:

答案 0 :(得分:1)

任何CPU都是问题。

您可以选择x64或x86平台。

  1. 确保已添加对CefSharp.Winforms nuget的引用

  2. 确保将解决方案的平台显式设置为x86 / x64,而不是任何CPU。

  3. 在配置文件中添加以下运行时绑定:

    dataset = tf.data.Dataset.from_tensor_slices(dataset)

  4. CSProj文件应设置以下属性:

    <runtime> <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> <probing privatePath="x86"/> </assemblyBinding> </runtime>

请参阅this article-逐步介绍了在Winforms中设置CEFSharp浏览器的过程。