views:

1466

answers:

4

My solution includes these two projects:

  • MyNamespace.Web.UI
  • MyNamespace.Web.Core

UI references Core, and Core references Foobar.dll, which exists nowhere except my library. When I build from Visual Studio 2008 Foobar.dll is in the UI project's Bin folder as expected. I have made certain it was not there before the build.

But when I build from NAnt, it is not there, which results in a runtime exception. Here's what the NAnt task looks like:

<target name="compile" depends="init">
    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
       commandline="${solution.file} /m /t:Clean /p:Configuration=${project.config} /v:q" workingdir="." />
    <exec program="${framework::get-framework-directory(framework::get-target-framework())}\msbuild.exe"
       commandline="${solution.file} /m /t:Rebuild /p:Configuration=${project.config} /v:q" workingdir="." />
</target>

In VS I have tried building, rebuilding, rebuilding all in release mode and debug mode, etc. It's always the same. Foobar.dll is in the Bin folder. Not so with NAnt. I have tried also to remove the /m switch from the NAnt script. Same result.

There are several other dlls referenced in Core and not in UI, and they appear in Bin as expected after the NAnt build.

My workaround is to reference Foobar.dll in the UI project, but that makes me a little nauseous. Any idea what can cause this?

(Incidentally Foobar.dll is actually NHibernate.ProxyGenerators.CastleDynamicProxy.dll)

A: 

In some things that I've worked on, I've resorted to using NAnt's copy task to copy the DLL into the bin directory so that the project will build. I don't know if that's necessarily best practice, but it works.

Rich Reuter
+1  A: 

I've used the MSBuild task in NantContrib before and it seemed to copy the library dlls into the bin folder. Granted this doesn't really explain why your approach doesn't work, but I'm assuming your goal is to get it to build, not figure out why it won't build

Jacob Adams
+2  A: 

You likely have the option in VS to "Copy Local" on, which is implicitly, well, copying it locally before the build. You'll need to emulate that in NAnt.

Similar to why you can just do a "Publish" for a web project from Visual Studio, but for the command line you have to both build and then copy out the output to wherever you are going.

Cory Foy
A: 

I agree with Cory. Since you are shelling out to msbuild you need to make sure you copy any 3rd party (yours or otherwise) dlls into your bin or output folder.

You can use the task to do this in nant before you run the tasks. then everything should be fine.

The only gotcha would be that you would have to know where to put it before the msbuild tasks run so you may have to create the folder structure first and hope msbuild does not wipe it out.

Hope that helps.

Joshua Cauble