有没有办法在没有AnyCPU的情况下构建VS单元测试

时间:2017-04-23 21:16:01

标签: c# visual-studio unit-testing cefsharp anycpu

我为HTML5 + JavaScript库开发了一个C#API - 我使用CefSharp作为中间层。现在我需要创建一些单元测试,以便我确信API有效。问题是CefSharp不能(简单地)与AnyCPU一起使用,而VisualStudio的单元测试必须为AnyCPU构建。当我尝试运行测试时,这会导致错误:CefSharp.Common will work out of the box if you specify platform (x86/x64).

有没有办法超越任何一个限制?
我知道CefSharp在某种程度上可以与AnyCPU兼容,但我无法让它运行。

修改

现在我没有收到第一个错误,但我还有另一个错误:

System.IO.FileNotFoundException: Could not load file or assembly CefSharp, Version=57.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138 or one of its dependencies. The specified module could not be found.
File name: CefSharp, Version=57.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138
   in CefSharp.CefSharpApp.OnBeforeChildProcessLaunch(CefSharpApp* , scoped_refptr<CefCommandLine>* commandLine)

这是Fusion View的日志:

LOG: This bind starts in default load context.
LOG: Using application configuration file: C:\PROGRAM FILES (X86)\MICROSOFT VISUAL STUDIO 14.0\COMMON7\IDE\COMMONEXTENSIONS\MICROSOFT\TESTWINDOW\vstest.executionengine.x86.exe.Config
LOG: Using host configuration file: 
LOG: Using machine configuration file from C:\Windows\Microsoft.NET\Framework\v4.0.30319\config\machine.config.

LOG: Post-policy reference: CefSharp, Version=57.0.0.0, Culture=neutral, PublicKeyToken=40c4b6fc221f4138

LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/CefSharp.DLL
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/CefSharp/CefSharp.DLL
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/CefSharp.DLL
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/CefSharp/CefSharp.DLL
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/CefSharp.EXE
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/CefSharp/CefSharp.EXE
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/CefSharp.EXE
LOG: Attempting download of new URL file:///C:/PROGRAM FILES (X86)/MICROSOFT VISUAL STUDIO 14.0/COMMON7/IDE/COMMONEXTENSIONS/MICROSOFT/TESTWINDOW/Extensions/CefSharp/CefSharp.EXE

相关GitHub问题here

如果您对我的代码感兴趣到目前为止: GitHub link(不太相关)

1 个答案:

答案 0 :(得分:0)

第一个问题

我发现设置Test>Test Settings>Default Architecture还不够,我还必须将整个项目设置为x86或{{1} }。首先,您必须打开配置管理器。

Configuration Manager

然后,您需要为测试项目创建x64x82平台。

Add new platform

请务必注意Visual Studio中的the most overlooked checkbox。如果您创建的平台不存在于解决方案的任何其他项目中,则需要检查此复选框,否则请取消选中。我确定这也是Visual Studio中最无用的复选框,如果您愿意,可以vote for its removal

Create platform, don't overlook checkbox

现在您的测试将针对您选择的平台构建!

第二个问题

这是another SO question的副本,可能是由于CefSharp是用C ++ / CLI编写的NuGet包。我不是很了解这个,而是GitHub上的一个聪明人found a solution