简体   繁体   English

在x64 C ++ / CLI上的MSTest

[英]MSTest on x64 C++/CLI

I got a problem using MSTest on x64: The test project depends on a couple of C++/CLI assemblies, and fails to load for some reason. 我在x64上使用MSTest时遇到问题:测试项目依赖于几个C ++ / CLI程序集,由于某种原因无法加载。 In Visual Studio, I get (stripped down): 在Visual Studio中,我得到了(简化):

Error loading D:\\xxx\\Xxx.Test.dll: Unable to load the test container 'D:\\xxx\\Xxx.Test.dll' or one of its dependencies. Error details: System.BadImageFormatException: Could not load file or assembly 'Common.Geometry.Native, Version=1.1.4574.22395, Culture=neutral, PublicKeyToken=null' or one of its dependencies. An attempt was made to load a program with an incorrect format.

Running MSTest manually in a command prompt, I get: 在命令提示符下手动运行MSTest,我得到:

Unable to load the test container 'D:\\xxx\\Xxx.Test.dll' or one of its dependencies. Error details: System.IO.FileNotFoundException: Could not load file or assembly 'Common.Geometry.Native, Version=1.1.4574.22395, Culture=neutral, PublicKeyToken=null' or one of its dependencies. The system cannot find the file specified.

Details worth mentioning: 值得一提的细节:

  • The test project itself is compiled using 'Any Cpu'. 测试项目本身使用“ Any Cpu”进行编译。
  • I use a x64 specific testrunconfig 我使用x64专用的testrunco​​nfig
  • Dependency walker shows no missing native dependencies in the C++/CLI assembly (Common.Geometry.Native) 依赖关系遍历器在C ++ / CLI程序集(Common.Geometry.Native)中没有丢失本机依赖项
  • Even more interesting, there is another test project in the same solution using the same C++/CLI assembly (Common.Geometry.Native), and it runs without any problems. 更有趣的是,在同一解决方案中,使用相同的C ++ / CLI程序集(Common.Geometry.Native),还有另一个测试项目,它可以毫无问题地运行。

I have also verified that there are no 32bit assemblies/dlls interfering. 我还验证了没有32位程序集/ dll干扰。

Any suggestions is welcome ! 欢迎任何建议!

I'd initially thought that microsoft didn't add a 64-bit capable test runner for MSTest until 2012... As it turns out, VS2010 is capable of this. 最初,我以为Microsoft直到2012年才为MSTest添加具有64位功能的测试运行程序。事实证明,VS2010可以实现这一功能。

What I'd check then is if your native dll has any other native dependencies. 然后,我要检查的是您的本机dll是否具有任何其他本机依赖项。

MSTest has a "mis-feature" where, before running your tests, it creates a temp directory, usually something like PC-NAME WORKSPACE_NAME 1782368124\\Out , and it copies your code into that directory. MSTest具有“错误功能”,在运行测试之前,它会创建一个临时目录,通常类似于PC-NAME WORKSPACE_NAME 1782368124\\Out ,并将代码复制到该目录中。 For .NET assemblies, it can figure out the dependencies and is able to copy them, but for native code it does not appear to do this. 对于.NET程序集,它可以找出依赖关系并能够复制它们,但是对于本机代码,它似乎没有这样做。

I've solved this in the past by adding the directory containing any other native dependencies to the PATH environment variable for my user account (remember if you do this to restart visual studio as it won't notice) 过去,我已经通过将包含任何其他本机依赖项的目录添加到我的用户帐户的PATH环境变量中来解决了这一问题(请记住,如果您这样做是为了重启Visual Studio,因为它不会引起注意)

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

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