简体   繁体   English

Visual Studio单元测试32位和64位

[英]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. 我有一个包含C ++和C ++ / CLI代码的项目的解决方案,以及一组使用Microsoft Unit Test Framework对所有这些进行单元测试的项目。 For the C++/CLI projects, the unit test projects are C# unit tests. 对于C ++ / CLI项目,单元测试项目是C#单元测试。 What I currently have is a platform for 32- and 64-bit. 我目前拥有的是32位和64位平台。 Also, for each platform I have unit test projects set to 32- and 64-bit platforms to match. 此外,对于每个平台,我将单元测试项目设置为32位和64位平台以匹配。

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. 我遇到的问题是,当我切换到32位与64位时,我需要转到TEST > TEST SETTINGS > DEFAULT PROCESSOR ARCHITECTURE并根据需要从32-和64翻转。 If I don't, I get a warning from Visual Studio that a 64-bit image cannot run in a 32-bit process. 如果不这样做,我会收到Visual Studio的警告,即64位映像无法在32位进程中运行。 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" 此外,我已尝试将单元测试项目设置为AnyCPU,但此操作失败并显示“尝试加载程序格式不正确”的错误

Is there a better way perhaps? 还有更好的方法吗?

If you're looking to automate test run ia 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. 如果您希望自动化测试运行ia构建机器,您可以将项目设置为AnyCPU并运行corflags / 32bit +(或/ 32bit-)以在运行单元测试之前将.NET程序集设置为正确的平台。

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. 我不知道VS的自动解决方案,然后有两个项目(一个x64和x86)链接到相同的文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM