Tim Scott
Tim Scott

Reputation: 15205

Build Via NAnt vs Visual Studio - One dll Missing

My solution includes these two projects:

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)

Upvotes: 2

Views: 2374

Answers (5)

Hinesh Mandalia
Hinesh Mandalia

Reputation: 1

I have had a similar issue. I solved this by explicitly adding

<Private>True</Private>

within the reference in the .csproj file which should force copy local.

<Reference Include="Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35, processorArchitecture=MSIL">
  <SpecificVersion>False</SpecificVersion>
  <HintPath>..\lib\Microsoft.Web.Infrastructure.1.0.0.0\lib\net40\Microsoft.Web.Infrastructure.dll</HintPath>
  <Private>True</Private>
</Reference>

Upvotes: 0

Joshua Cauble
Joshua Cauble

Reputation: 1349

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.

Upvotes: 0

Cory Foy
Cory Foy

Reputation: 7222

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.

Upvotes: 2

Jacob Adams
Jacob Adams

Reputation: 4004

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

Upvotes: 1

Rich Reuter
Rich Reuter

Reputation: 610

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.

Upvotes: 0

Related Questions