Tag Archive for msbuild
07
Jul 2009
Generating NHibernate Database Schema with a MSBuild Task
Today I need something really particular with NHibernate, I need to generate a “test” database schema from my MSBuild task in a particular Target. I know, there are simple options like use hbm2ddl (part of the NHibernate distribution) and this simple Mike Nichols’ MSBuild task but I want to use the hibernate configuration file.
This is my first attempt to do this in a MSBuild task, write this task in MSBuild was a very trivial code exercise, I need to improve it and get more things done, but right now I think is enough to get the job done.
The usage is very simple:
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003"
DefaultTargets="Test">
<PropertyGroup>
<NHibernateConfig>hibernate.cfg.xml</NHibernateConfig>
</PropertyGroup>
<ItemGroup>
<TestDatabase Include="./test.db" />
</ItemGroup>
<UsingTask AssemblyFile="../bin/Rioshu.Msbuild.dll"
TaskName="NHibernateSchema" />
<Target Name="Test">
<Delete Files="@(TestDatabase)"
Condition="Exists('@(TestDatabase)')" />
<NHibernateSchema ConfigurationFile="$(NHibernateConfig)"
Export="true" />
</Target>
</Project>
You can grab the bytes here: NhibernateSchemaMSBuildTask.zip
