All posts tagged '.net'

.NET Musings

Wandering thoughts of a developer, architect, speaker, and trainer


Compiling NHibernate 2.0 in VS2008

I recently saw Len Smith's talk on NHibernate at the Lansing Day of .Net, and thought I'd give it a spin.

Note: This post has been updated for Beta 2 CR2 GA

First pass (if you want to keep the 2.0 compatibility in the solution) is to create copies of all of the project files for the 3.5 FW and VS 2008 (Some are included, but you will need to create Iesi.Collections-3.5.proj, Iesi.Collections.Test-3.5.proj, NHibernate.Examples-3.5.csproj, NHibernate.Test.Performance-3.5.csproj, and NHibernate.Tool.HbmXsd-3.5.csproj.) Then, make a copy of the included NHibernate.Everything.2.0 solution file and name it NHibernate.Everything.3.5. Open in your favorite text editor and change all of the references from the <project name>-2.0 projects to <project name>-3.5.
NHibernate.Tool.HbmXsd does not have a "2.0" in it's name, so you will need
to add the "-3.5" suffix to the project name and file. Also, change the Format Version from 9.00 to 10.00 (first line of content), and change the second line to read # Visual Studio 2008. Then, open the everything solution in VS 2008. Since the project files have been modified to include the BaseIntermediateOutputPath, will be prompted with a security dialog. Just select to load the projects normally. You will also be prompted if you want to convert NHibernate.Example.Web to the 3.5 framework. If you are running against the 3.5 FW, say yes. All of the project files will then be converted to the VS 2008 format. As a final step (again if you are running against the 3.5 FW), convert each project to target 3.5 (Properties/Application/Target Framework).

First pass wouldn't compile through the IDE (this has been reintroduced since Beta 2) Turns out that there are some files missing from the NHibernate-3.5 project: SqlTypes\SqlXMLType.cs, Type\ClassMetaType.cs, and Transaction\ISynchronization.cs.

If you don't have nUnit installed (I prefer MbUnit), then some references will be out of whack - delete nunit.framework from the references and then add it back in from the included lib directory to the Iesi.Collections.Test-3.5 and NHibernate.Examples.3.5 projects. Also, you can delete the references to nMock and Oracle.Data.Access from the NHibernate.Test-3.5 project.

The project now builds, and you can run the unit tests after a few more setup tasks and tweaks. First, change the connection string in "hibernate.cfg.xml" and correct the connection string to match your database. Secondly, create the database in your environment. For SqlServer, the default is NHibernate, but you can name it whatever you wish as long as the connections strings match. Next, go into the NHSpecificTest directory, navigate to NH1098 and change the mapping file (Mappings.hbm.xml) to be an Embedded Resource. For NH1301 and NH1313, include the mapping files in the project (if you don't see them make sure "Show All Files is on for the project) and set them to be Embedded Resources. You are now ready to run the tests with your favorite test runner (I use ReSharper and MbUnit with the MbUnit plug in) There are a significant number of tests that are excluded from the test projects, but first pass through, just run the tests that are currently in the build. You should get all passes with a few failures for ignored tests (there is an issue with how some of the test fixtures are coded that cause failures instead of ignores - by calling Assert.Ignore anywhere except in a Test method causes a reported failure instead of an ignore.). So look closely at the results.

You will also want to copy the NHibernate Schemas to Visual Studio (See how here).

In the NHibernate.Test-3.5 project, in the NHSpecificTest directory, NH1077,
NH1101, NH1300, NH1304, NH1332, NH1355, NH1362, NH1383, NH1399, NH1403, NH1405,
NH1408, NH1413, NH1419 and NH693 directories were not included in the solution (I added them and their files). Under the root of the project, GeneratedKeys and OnDelete are not included into the project, and should be. For each of these tests (except NH1399, since it doesn't have one) you need to change the mapping files' "Build Actions" to Embedded Resource. The mapping files are the XML files in each of the directions. Pay close attention, since NH693 has two and OnDelete has three. (For those of you following along with my posts, NH1355 is the test for the fix for the SQL Server TimeStamp column.)

The unit tests in NHibernate.Test.Performance-3.5 in the Performance test fixture will fail unless the app.config file is modified to include the "prepare_sql" property:
<property name="prepare_sql">true</property>

Finally, copy nunit.*.dll, log4net.*, NHibernate.dll, Castle.Core.dll, Castle.DynamicProxy2.dll, and Iesi.Collections.dll from \lib\net\2.0 to your directory of choice, and have at it.

Happy coding!

Managed Windows Shared Hosting by OrcsWeb