Member Menu
 
 Monthly JBoss newsletter:
 
Java Persistence with Hibernate
CaveatEmptor

How To Build and Test NHibernate

This page describes how to build and test NHibernate either from the packaged distribution or from CVS using NAnt and NUnit or Visual Studio .NET and TestDriven.NET.


Using NAnt and NUnit

What external programs do I need to build NHibernate?

NHibernate relies on the .NET Framework Version 1.1 (it can work with .NET 1.0 with some minors changes, but it is not recommended), NAnt 0.85-rc3 for building, and NUnit 2.2 for testing (included in the distribution). You don't have to be too familiar with these tools to build NHibernate - just willing to edit XML files and open the Command Prompt.

  1. Make sure you have the .NET Framework SDK Version 1.1 - basic development or testing have been done with .net-1.0, but you will have to do some minors changes to compile it. You do NOT need Visual Studio .NET 2003 to compile NHibernate. However, you can certainly use it to compile NHibernate. To build NHibernate 1.0.1 you need version 2.0 of the .NET Framework runtime (SDK is not required). Version 2.0 is needed to run ILMerge.
  2. Download and install NAnt 0.85-rc3.
  3. (optional) Download and install NUnit 2.2 if you want to run the NUnit tests after the build. We have included the NUnit.Framework.dll in the lib folder so you don't have to have the full NUnit installed on your machine.

For convenience, you will probably want to add NAnt (and optionally NUnit GUI) to your PATH. It is not needed but makes for less typing at the command prompt.

Let's build NHibernate now!

Now that we have all of the prerequisites out of the way, on to the fun stuff:

  1. Download the code from sourceforge.net. You can either use the file releases or the CVS pserver protocol to get the NHibernate code. The file release will contain already built DLLs, but they will probably be old DLLs compared to what will be built with the code in CVS.
  2. Open the Command Window and change to the nhibernate directory.
  3. I am assuming you have NAnt in your path. For the debug build type the command:
NAnt -D:project.config=debug clean build >output-debug-build.log

For the release build type the command:

NAnt -D:project.config=release clean build >output-release-build.log

This will create a build folder under the nhibernate folder.

That is all you have to do to build NHibernate from source. Of course, we want to test what was just built.

Let's run the tests for NHibernate

Now we have NHibernate.dll, NHibernate.DomainModel.dll, and NHibernate.Test.dll all built. The NHibernate.DomainModel.dll and NHibernate.Test.dll are only needed for testing. Your projects require no reference to them and should not reference them.

Tests require access to a database. Any supported database server can be used. It's best to create a separate user and database for NHibernate tests. You also have to ensure that NHibernate can load ADO.NET drivers for your database, so copy the driver assembly to the same directory that contains the built NHibernate files or put it in the GAC (MS SQL Server 2000 driver is already put in the GAC during .NET Framework installation, so no special steps need to be taken if you are going to use this database). Part of the NAnt build is to copy the App.config file from NHibernate.Test into the bin as NHibernate.Test.dll.config while overwriting connection settings in the file by those specified on the command line. To run the test type a command such as this (all on a single line):

NAnt
    -D:project.config=release
    -D:nhibernate.dialect="NHibernate.Dialect.MsSql2000Dialect"
    -D:nhibernate.connection.driver_class="NHibernate.Driver.SqlClientDriver"
    -D:nhibernate.connection.connection_string="Server=localhost;initial catalog=nhibernate;User ID=blah;Password=blah;Min Pool Size=2"
    test
    >output-release-test.log

The command above was split into multiple lines for readability, but it should be typed in as a single long line. You should set the properties to whatever you use to connect to your database.

If you want to use the NUnit GUI to run the test, the file src\NHibernate.Test\NHibernate.Test.nunit stores all of the settings.

The NAnt test target and the NUnit GUI will output the results of the text to the file NHibernate.Test.dll-results.xml. If the NAnt test target is run it will output the results in the bin folder. If the NUnit GUI is used to run the test the results will be output to the NHibernate.Test folder.

Using Visual Studio .NET and TestDriven.NET

  1. Download and install TestDriven.NET add-in for Visual Studio from http://www.testdriven.net/.
  2. Load the NHibernate-1.1 solution into Visual Studio.
  3. Edit connection settings in App.config in the NHibernate.Test project.
  4. Go through all AssemblyInfo.cs files and comment out the line referencing NHibernate.snk, if present.

Now you can build the solution and run the tests using TestDriven.NET.

Building the HtmlHelp2 help collections (optional)

To build the help files for Visual Studio .NET, you will need the Microsoft Visual Studio Help Integration Kit (VSHIK) installed on your PC. This requires Visual Studio .NET (although there is a workaround - see http://helpware.net/mshelp2/h2faq.htm#novsnet).

You will also need to have NDoc installed, and copy the following files from NDoc into your NAnt lib folder (see http://nant.sourceforge.net/release/latest/help/tasks/ndoc.html):

  • NDoc.Documenter.Msdn2.dll
  • NDoc.Documenter.Msdn2.xml
  • NDoc.Documenter.NativeHtmlHelp2.dll
  • Interop.MSHelp.Compiler.dll

Finally, include the NAnt command-line argument -D:vshik.installed=true when building help files to generate VS.NET output. If VSHIK is not installed in the default location of C:\Program Files\Microsoft Help 2.0 SDK, you will also need to specify the correct install path using -D:vshik.path=<path>.


  NEW COMMENT

vs2005 16 Feb 2006, 16:39 jmcfet
many of us have moved onto VS2005 and are trying to implement projects
using nHibernate. was wondering if there was a VS2005 solution to use
instead of Nant. As good as nAnt is we would much prefer a VS2005
solution. I am trying to build one right now so we can debug a problem
that appears to in nHibernate (many-to-one) cause exception but after
the query is finished.
 
Please clarify AssemlyInfo.cs 18 Aug 2006, 15:01 mteper
The AssemblyInfo.cs files are missing from the trunk in SVN. Please 
clarify what should be done to build the project.
 
Missing AssemblyInfo.cs - solution 06 May 2007, 21:57 nblumhardt
Hi,  (at) mteper, in regards to the missing AssemblyInfo (dot) cs files - cd to the
/trunk/nhibernate directory, execute:

nant set-net-2.0-framework-configuration visual-studio

This should regenerate AssemblyInfo.cs.

If you get an error because of a dependency on 'clover' just comment
that section out of build-common/common.xml.
 
Getting NHibernate 2.0 built 05 Feb 2008, 08:38 skaue
Here's what I did:

 * Download latest NAnt (I dl 0.86 beta1)
 * Follow installation guide to make the nant.bat etc (see website)
 * Go to folder where default.build is located (command prompt)
 * run "nant -t:net2-0 visual-studio"
 * Open sln in Visual Studio and voila

At least, this is how I did it.
 
© Copyright 2006, Red Hat Middleware, LLC. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc. [Privacy Policy]