Search code examples
c#visual-studiounit-testingcefsharpanycpu

Is there a way to build VS unit tests without AnyCPU


I develop a C# API for a HTML5+JavaScript library – I use CefSharp as the intermediate layer. Now I need to create some unit tests so that I'm sure the API works. The problem is that CefSharp cannot be (simply) used with AnyCPU whereas VisualStudio's unit tests MUST be built for AnyCPU. This results in an error when I try to run the tests: CefSharp.Common will work out of the box if you specify platform (x86/x64).

Is there a way to overpass any one of these limitations?
I know CefSharp sould be somehow compatible with AnyCPU but I was unable to get it running.


EDIT

Now I don't recieve the first error, but I've got another one:

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)

.

This is the Fusion View's log:

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

Related GitHub issue here.

If you were interested in my code so far: GitHub link (not really relevant)


Solution

  • First problem

    I found out it's not enough to set Test>Test Settings>Default Architecture, I also had to set the whole project to build as either x86 or x64. First you have to open the Configuration Manager.

    Configuration Manager

    .

    Then you need to create the x86 and x64 platforms for your testing project.

    Add new platform

    .

    Be sure to notice the most overlooked checkbox in Visual Studio. This checkbox needs to be checked if the platform you're creating doesn't exist in any other project of your solution and unchecked otherwise. I'm sure this is also the most useless checkbox in Visual Studio, you can vote for its removal if you feel like it.

    Create platform, don't overlook checkbox

    Now your tests will be built for the platform you choose!

    .

    Second problem

    This is a duplicate of another SO question and is probably caused by CefSharp being a NuGet package written in C++/CLI. I don't really understand this but a wise man on GitHub found a solution.