简体   繁体   中英

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. 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:

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:

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. These paths were relative the Nunit install location on my local machine and the server isn't structured the same.

If you look at the properties in Visual Studio you wont see any mention of these hint-paths. Open up the relevant csproj in a text editor and you'll see something that looks like this:

  <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. Open the solution and click Build=>Configuration Manager from the bar at the top. In the active solution platform I just had 'x86'. Select 'New' from the drop down and pick 'AnyCpu', then choose to copy settings from '', and leave create new project platforms ticked. Thats it! Click ok, close the config manager and then do a ctrl+shift+S to save all (including csproj + sln).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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