1

我们有一个 .net 4.6.2 项目,它在 AnyCPU 上以“首选 32 位”的形式分发,并且正在使用 CefSharp,其软件包同时具有 x86 和 x64 版本。

按照 CefSharp 项目中添加 AnyCPU 支持的建议(选项 1),我执行了以下操作:

  1. 在我的 .csproj 文件中的第一个添加了 true
  2. 在我的 app.config 文件中添加了以下内容:
     <runtime>
         <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
             <probing privatePath="x86"/>
         </assemblyBinding>
     </runtime>
  1. 如前所述,我所有的项目配置都设置为“首选 32 位”
  2. 在启动时初始化 Cef:
var settings = new CefSettings();
settings.BrowserSubprocessPath = @"x86\CefSharp.BrowserSubprocess.exe";

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

在调试中一切正常,但是当我尝试构建我的发布版本时,我得到一个错误 - 使用详细模式:

2>SGEN:错误:无法加载文件或程序集“CefSharp.Core.dll”或其依赖项之一。指定的模块无法找到。

再往上,我可以看到它传递了以下对 SGEN 的引用:

2> 参考= 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.Common.63.0.2\build..\CefSharp\x86\CefSharp.Core.dll 2>C:\SVN\MySolution\Branches \MyBranch\packages\CefSharp.Common.63.0.2\build..\CefSharp\x86\CefSharp.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.WinForms.63.0.2\build.. \CefSharp\x86\CefSharp.WinForms.dll

这似乎来自 CefSharp.Common.props 文件:

  <ItemGroup>
    <Reference Include="CefSharp">
      <HintPath>$(MSBuildThisFileDirectory)..\CefSharp\x86\CefSharp.dll</HintPath>
      <Private>False</Private>
    </Reference>
    <Reference Include="CefSharp.Core">
      <HintPath>$(MSBuildThisFileDirectory)..\CefSharp\x86\CefSharp.Core.dll</HintPath>
      <Private>False</Private>
    </Reference>
  </ItemGroup>

或 CefSharp.Common.targets 文件:

<ItemGroup>
  <CefSharpCommonBinaries32 Include="$(MSBuildThisFileDirectory)..\CefSharp\x86\*.*" />
  ...
</ItemGroup>

如果它是文件名的“build..”部分没有被 SGEN 解析,我尝试硬编码“$(MSBuildThisFileDirectory)..”(我不想真正这样做的原因有很多;但这是一个测试)但遇到了完全相同的问题,但正确的绝对路径作为对 SGEN 的引用传入:

2> 参考= 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.Common.63.0.2\CefSharp\x86\CefSharp.Core.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages \CefSharp.Common.63.0.2\CefSharp\x86\CefSharp.dll 2>C:\SVN\MySolution\Branches\MyBranch\packages\CefSharp.WinForms.63.0.2\CefSharp\x86\CefSharp.WinForms.dll

这给我留下了为什么 SGEN 无法加载 dll 的问题。所以,我目前的想法是,这是由于缺少依赖。我应该期待这个参考列表中的 libcef.dll 吗?我已将其他软件包添加到我的 .csproj 文件中:

<Import Project="..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props" Condition="Exists('..\packages\cef.redist.x86.3.3239.1723\build\cef.redist.x86.props')" />
<Import Project="..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props" Condition="Exists('..\packages\cef.redist.x64.3.3239.1723\build\cef.redist.x64.props')" />

我还尝试注释掉上面的第二个/x64 导入行,但无济于事。

[更新] 我刚刚打开了 Fusion 日志记录(根据 Yavor Georgiev 关于 SGEN 错误的博客文章),据此 dll 加载正常。

4

1 回答 1

3

在我接手的一个遗留 VB.Net WinForm 项目中,我遇到了类似的问题。将旧的 WebControl 换成 CefSharp 后,我们可以在 Debug 模式下构建和运行就好了,但是 Release 构建会失败。

我注意到构建错误中列出的文件是 SGEN - XmlSerializationGenerator。

据我所知,没有需要 XmlSerializtion 的对象,所以我转到项目属性 > 编译 > 高级编译选项并将“生成序列化程序集:”从自动更改为否。

该解决方案现在在发布模式下构建和运行得很好。

于 2019-05-23T16:56:30.213 回答