我有一个被设置为Any CPU的dll。我正在使用CefSharp nuget包,并希望通过NUnit和Visual Studio运行一些单元测试。我正在使用程序集解析器来解决,请按照https://github.com/cefsharp/CefSharp/issues/1714此处的选项2所述选择正确的CefSharp版本。
问题是当我尝试调用它时:
private static void InitialiseCefBrowser()
{
var settings = new CefSettings
{
// Set BrowserSubProcessPath based on app bitness at runtime
BrowserSubprocessPath = Path.Combine(Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location),
Environment.Is64BitProcess ? "x64" : "x86",
"CefSharp.BrowserSubprocess.exe")
};
// Make sure you set performDependencyCheck false
Cef.Initialize(settings, performDependencyCheck: false, browserProcessHandler: null);
}
我得到:
The active test run was aborted. Reason: Unhandled Exception: System.IO.FileNotFoundException:
Could not load file or assembly 'CefSharp, Version=65.0.0.0,
Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of
its dependencies. The system cannot find the file specified.
at CefSharp.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp* , scoped_refptr<CefCommandLine>* commandLine)
Unhandled Exception: System.IO.FileNotFoundException: Could not
load file or assembly 'CefSharp, Version=65.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138' or one of its dependencies. The system cannot find the file specified.
at CefSharp.CefSharpApp.OnContextInitialized(CefSharpApp* )
我运行了融合日志查看器,似乎dll被加载了两次。第一次加载所有文件都很好,并且可以在测试项目的bin文件夹中找到它。然后看起来好像在另一个位置:
第一次:
Running under executable C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\testhost.x86.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = CefSharp, Version=65.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138
(Fully-specified)
LOG: Appbase = file:///C:/MyApp/Source/MyAppTests/bin/Debug/
第二次:
Running under executable C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO\2017\ENTERPRISE\COMMON7\IDE\EXTENSIONS\TESTPLATFORM\testhost.x86.exe
--- A detailed error log follows.
=== Pre-bind state information ===
LOG: DisplayName = CefSharp, Version=65.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138
(Fully-specified)
LOG: Appbase = file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO/2017/ENTERPRISE/COMMON7/IDE/EXTENSIONS/TESTPLATFORM/
显然找不到它。
什么是设置Appbase的设置,我如何控制它,以便它在正确的位置查找dll?就像我几乎需要在单元测试中处理程序集解析一样。