当无法在项目中引用DLL时,如何让单元测试针对相应的DLL运行?

时间:2023-01-14 12:18:41

I've got the following "Pre Build Event" working for my powershell builds (including our Continuous Integration). It simply moves a DLL into the output directory based on the Processor Architecture.

我已经为我的powershell构建(包括我们的持续集成)提供了以下“预构建事件”。它只是根据处理器体系结构将DLL移动到输出目录中。

if '$(PROCESSOR_ARCHITECTURE)'=='AMD64' (copy /y "$(ProjectDir)x64\sqlite3.dll" "$(OutDir)") 
if '$(PROCESSOR_ARCHITECTURE)'=='x86' (copy /y "$(ProjectDir)x86\sqlite3.dll" "$(OutDir)")
if '$(PROCESSOR_ARCHITEW6432)'=='AMD64' (copy /y "$(ProjectDir)x64\sqlite3.dll" "$(OutDir)")

The problem I'm running into is when I run the Resharper Unit Tests within the IDE. When I do this, the Pre Build event doesn't run, and therefore all of the tests that depend on the sqlite3.dll fail.

我遇到的问题是我在IDE中运行Resharper单元测试。当我这样做时,Pre Build事件不会运行,因此依赖于sqlite3.dll的所有测试都会失败。

What I need to do is either be able to move the appropriate file into the output directory before the Test Runner runs, OR make sure the Test Runner runs against ONLY the x86 Architecture, whereby I can just drop the appropriate file in the bin\debug folder and be done with it.

我需要做的是能够在Test Runner运行之前将相应的文件移动到输出目录中,或者确保Test Runner仅针对x86架构运行,我可以将相应的文件放在bin \ debug中文件夹,并完成它。

Things I've tried:

  1. I've tried setting the "Build Settings" to "Always Build" but this has no affect on the outcome. It appears as though the build in the IDE doesn't run the Pre Build Event
  2. 我已经尝试将“Build Settings”设置为“Always Build”,但这对结果没有影响。似乎IDE中的构建不会运行预构建事件
  3. I've also tried to set the default platform architecture in [Resharper -> Options -> Tools -> Unit Testing] - as per the docs, but unfortunately my version of R# doesn't have that option (7.1.3)
  4. 我还尝试在[Resharper - >选项 - >工具 - >单元测试]中设置默认平台架构 - 根据文档,但不幸的是我的R#版本没有该选项(7.1.3)

1 个解决方案

#1


1  

You can force the C# project to be 32 bit only, and the ReSharper runner will only run it as 32 bit. That way, you can drop the x86 dll in the bin\debug folder and it should all just work.

您可以强制C#项目仅为32位,而ReSharper运行器仅将其作为32位运行。这样,您可以将x86 dll放在bin \ debug文件夹中,它应该都可以正常工作。

#1


1  

You can force the C# project to be 32 bit only, and the ReSharper runner will only run it as 32 bit. That way, you can drop the x86 dll in the bin\debug folder and it should all just work.

您可以强制C#项目仅为32位,而ReSharper运行器仅将其作为32位运行。这样,您可以将x86 dll放在bin \ debug文件夹中,它应该都可以正常工作。