我们有一个 .net 4.6.2 项目,它在 AnyCPU 上以“首选 32 位”的形式分发,并且正在使用 CefSharp,其软件包同时具有 x86 和 x64 版本。
按照 CefSharp 项目中添加 AnyCPU 支持的建议(选项 1),我执行了以下操作:
- 在我的 .csproj 文件中的第一个添加了 true
- 在我的 app.config 文件中添加了以下内容:
<runtime>
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
<probing privatePath="x86"/>
</assemblyBinding>
</runtime>
- 如前所述,我所有的项目配置都设置为“首选 32 位”
- 在启动时初始化 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 加载正常。