Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Remove NUnit reference for Release build

I have a project with many NUnit tests. I am happy for these tests to be included in the Debug configuration build but I would like to remove the dependency on nunit.framework for the Release configuration. Is there a way of excluding the NUnit reference and the nunit test objects for a specific (Release) configuration? I am using Sharp Develop but I am curious how you would approach this problem with Visual Studio as well.

Any clues?

like image 674
John Hartley Avatar asked Aug 31 '11 14:08

John Hartley


2 Answers

It sounds like you've got your tests in the same project as your release code. That's not a great idea - split the code into two projects, one with the tests and one with the production code. Only the test project will need to refer to NUnit.

That also means that none of the tests will ship with the release code, and it's easier to browse just the production code or just the test code.

like image 191
Jon Skeet Avatar answered Sep 24 '22 17:09

Jon Skeet


If you prefer to develop with my Unit Tests as a part of the project you're trying to test, you can add the following condition to both your unit test files and your nunit reference in the project file.

Condition=" '$(Configuration)'=='Debug' "

That will only include the nunit reference as well as your test classes in the build when you're in debug mode.

So your project file might have something like this:

<Reference Include="nunit.framework, Version=2.6.3.13283, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77, processorArchitecture=MSIL" Condition=" '$(Configuration)'=='Debug' ">
  <HintPath>..\packages\NUnit.2.6.3\lib\nunit.framework.dll</HintPath>
</Reference>

<Compile Include="UnitTests.cs" Condition=" '$(Configuration)'=='Debug' "/>
like image 31
propagated Avatar answered Sep 24 '22 17:09

propagated