I'm trying to write an MSBuild task to build a database using FluentNhibernate mappings.
The code for the task currently looks like this...
public class CreateDatabase : Task
{
[Required]
public string ConfigFile
{ get; set; }
[Required]
public string MappingAssemblyName
{ get; set; }
public override bool Execute()
{
var mappingAssembly = Assembly.Load(MappingAssemblyName);
var config = new Configuration();
config.Configure(ConfigFile);
var fluentConfig = Fluently.Configure(config)
.Mappings(m => m.FluentMappings.AddFromAssembly(mappingAssembly));
var sessionSource = new SessionSource(fluentConfig);
sessionSource.BuildSchema();
return true;
}
}
and the MSBuild usage looks like this...
<ItemGroup>
<Content Include="hibernate.cgf.xml" />
</ItemGroup>
<UsingTask AssemblyFile="..\lib\MyUtilities.MSBuild.dll" TaskName="CreateDatabase" />
<Target Name="Build" >
<CreateDatabase ConfigFile="@(Content)" MappingAssemblyName="MyMappingAssemlyName" />
</Target>
But now I'm stuck
Not surprisingly, Assembly.Load fails because the assembly containing my Fluent mappings ('MyMappingAssemly') isn't present.
Assuming that the Fluent mappings are defined within another project within my solution, what is the best way to tell my MSBuild task about the mapping assembly? I think I might be going down the wrong path using the 'MappingAssemblyName' property.