Jarek Mitek
Jarek Mitek

Reputation: 598

Visual Studio Unit Test 32-bit and 64-bit

I have a solution that has projects both with C++ and C++/CLI code, and a set of projects which unit test all of these, using the Microsoft Unit Test Framework. For the C++/CLI projects, the unit test projects are C# unit tests. What I currently have is a platform for 32- and 64-bit. Also, for each platform I have unit test projects set to 32- and 64-bit platforms to match.

The issue I have is that when I switch to 32-bit vs. 64-bit I need to go to TEST > TEST SETTINGS > DEFAULT PROCESSOR ARCHITECTURE and flip from 32- and 64 as needed. If I don't, I get a warning from Visual Studio that a 64-bit image cannot run in a 32-bit process. This makes sense, but surely there is some way to automate this? Otherwise if I do a batch build on a build machine I will not have control of this and the unit tests will fail.

Also I have tried to set the unit test projects to be AnyCPU but this fails with an error saying "An attempt was made to load a program with an incorrect format"

Is there a better way perhaps?

Upvotes: 11

Views: 4130

Answers (1)

Dror Helper
Dror Helper

Reputation: 30790

If you're looking to automate test run i a build machine you can set the project to AnyCPU and run corflags /32bit+ (or /32bit-) to set the .NET assembly to the right platform before running the unit tests.

I'm not aware of an automatic solution for VS other then have two projects (one x64 and on x86) that link to the same files.

Upvotes: 3

Related Questions