views:

31

answers:

1

I have the following project structure using a Domain Model, StructureMap and Fluent NHibernate:

Project Structure

The problem I'm having is that Fluent NHibernate requires all of the following to be the bin directory of the website for it to work at runtime:

  • Antlr3.Runtime.dll *
  • Castle.Core.dll
  • Castle.DynamicProxy2.dll
  • FluentNHibernate.dll *
  • Iesi.Collections.dll *
  • log4net.dll *
  • NHibernate.ByteCode.Castle.dll
  • NHibernate.dll *

The problem I'm having is that not all of these assemblies are output to my website's bin directory. Currently only the items with a * are output correctly. The items in bold are missing from the bin directory.

Now, I would of assumed that the reason for this is because I have not added them as references to my Fluent NHibernate project. The only references I currently have are to NHibernate.dll and FluentNHibernate.dll. These two references alone are enough to bring through the items marked with a *, but they do not bring through the missing items.

So, I then thought that to get them to all come through I'd just add them as references to the Fluent NHibernate project. Unfortunately, this made no difference; the same items were still missing from the bin directory.

I've never really understood how visual studios decides which assemblies to copy over. I always assumed it was any assembly marked as Copy Local=true, but this doesn't seem to be the case in this scenario.

Of course I could just add all the assembly references into Website, but then that'd completed defeat the point of loosely coupling the projects through StructureMap.

Does anyone have any idea why the assemblies are missing and how I can get them to copy over correctly?

+4  A: 

You can either add references to the project that requires those files be present in the output directory (Website in your case) or you can add a post-build step in your build script to copy them across.

This is a case of VS and the compiler being "smart" about whether references are actually required or not. The C# compiler optimizes out those references that aren't actually required. Adding a reference to non-required assembly in VS will ensure it appears in the output directory of that project. However, dependent projects will only get that same assembly if it's actually used by the project referencing it. That is, if the C# compiler hasn't optimized its reference out. That's why you would need to add the reference to the Website project, if you go that route.

Personally, I did exactly that. I don't really think this is tight coupling since NH still resolves the assemblies dynamically at runtime. And it's not like I can't just substitute in other byte code assemblies manually and restart my app. But it's also not like I would do that without adequate testing, so in a way I consider myself to be coupled to Castle on the basis of that. And, therefore, I'm not irked by the references.

HTH,
Kent

Kent Boogaart
Out of interest, why would you add the references when you could use the post build event and copy?
GenericTypeTea
I would copy them on a post-build step and keep the web-project clean from references.
jishi
@jishi: to each his own. To me, a post-build step in the Website project is just as much a statement of dependence as is adding the references.
Kent Boogaart