简体   繁体   English

如何获得要在构建机器上构建的NUnit测试项目?

[英]How do you get an NUnit test project to build on a build machine?

I've been struggling (not for the first time) to set up continuous integration on a project I've been working on. 我一直在努力(不是第一次)在我正在从事的项目上建立持续集成。 We use CruiseControl.NET, but that's not really been the problem - the majority of the problems have been to do with csproj + sln files and Visual Studio. 我们使用CruiseControl.NET,但这并不是真正的问题-大多数问题与csproj + sln文件和Visual Studio有关。 After some mucking about I managed to solve them but thought I'd document what must be very common problems. 经过一番摸索之后,我设法解决了这些问题,但以为我要记录一下必须是非常常见的问题。

After getting the ccnet configuration up and running, the first problem I ran into was a compile error: 在启动并运行ccnet配置后,我遇到的第一个问题是编译错误:

errorCS0234: The type or namespace name 'Gui' does not exist in the namespace 'NUnit' (are you missing an assembly reference?)

After resolving this another I got the familiar (and familiarly painful) 64 vs 32 bit problem: 解决了另一个问题后,我遇到了熟悉的(痛苦的)64 vs 32位问题:

System.BadImageFormatException: Could not load file or assembly '....' or one of its dependencies. An attempt was made to load a program with an incorrect format.

The first problem was caused by 'hint-paths' being added by Visual Studio when I referenced the NUnit dlls. 第一个问题是由Visual Studio在引用NUnit dll时添加的“提示路径”引起的。 These paths were relative the Nunit install location on my local machine and the server isn't structured the same. 这些路径是相对于我的本地计算机上Nunit安装位置的,并且服务器的结构不同。

If you look at the properties in Visual Studio you wont see any mention of these hint-paths. 如果您查看Visual Studio中的属性,您将看不到这些提示路径的任何提及。 Open up the relevant csproj in a text editor and you'll see something that looks like this: 在文本编辑器中打开相关的csproj,您会看到类似以下内容的内容:

  <HintPath>..\..\..\..\Program Files (x86)\NUnit 2.5.7\bin\net-2.0\framework\nunit.framework.dll</HintPath>

and replace it with something like this: 并将其替换为以下内容:

  <HintPath>$(ProgramFiles)\NUnit 2.5.7\bin\net-2.0\framework\nunit.framework.dll</HintPath>

In cruise control I was building against the solution file and not specifying what platform to target directly. 在巡航控制中,我是根据解决方案文件构建的,没有指定直接针对的平台。 This was causing the second problem. 这是造成第二个问题。 To fix this you can use Visual Studio. 要解决此问题,您可以使用Visual Studio。 Open the solution and click Build=>Configuration Manager from the bar at the top. 打开解决方案,然后从顶部的栏中单击Build => Configuration Manager。 In the active solution platform I just had 'x86'. 在主动解决方案平台中,我只有“ x86”。 Select 'New' from the drop down and pick 'AnyCpu', then choose to copy settings from '', and leave create new project platforms ticked. 从下拉列表中选择“新建”,然后选择“ AnyCpu”,然后选择从“复制设置”,并勾选“创建新项目平台”。 Thats it! 而已! Click ok, close the config manager and then do a ctrl+shift+S to save all (including csproj + sln). 单击确定,关闭配置管理器,然后执行ctrl + shift + S保存所有内容(包括csproj + sln)。

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

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