views:

287

answers:

3

How do I go about compiling a .net 3.5 class library into a dll with Nant (0.86)?

This is what I have so far:

How do I go about referencing a system dll in the GAC? This line done seem to work.

<include name="System.ComponentModel.DataAnnotations.dll"/>

This is my script:

<?xml version="1.0"?>
<project name="MyCorp.Data" default="all">

  <property name="debug" value="true" />

  <target name="all"/>

  <target name="clean" description="remove all build products">
    <delete dir="build"  if="${directory::exists('build')}" />
  </target>

  <target name="init">
    <mkdir dir="build" />
  </target>

    <target name="compile" 
            depends="init"
            description="compiles the application">
        <csc target="library" output="build\${project::get-name()}.dll" debug="${debug}">
            <sources>
                <include name="src\MyCorp.Data\**\*.cs" />                             
            </sources>
            <references>                        
       <include name="tools\subsonic\subsonic.dll"/>
       <include name="lib\log4net\log4net.dll"/>
       <include name="System.ComponentModel.DataAnnotations.dll"/>
            </references>                        
        </csc>
    </target>

</project>

I got this far by using JP Boodhoos post

+2  A: 

@Dan

If you would please list what version of .Net you are targeting? I am a new nAnt user, and the one item I learned quite quickly is that building Dll's and Executables that are targeting the 3.5SP1 framework needs to be done using the 0.86 beta bits instead of the 0.85 version you are on.

You can use 0.85, but then you need to call out to MSBuild tasks and link over to the solution/project files. This took me about a day of searching online to figure out.

Richard B
Thanks that useful info. Yeah im building a 3.5 app, so ill need the newer version of Nant
Dan
+2  A: 

You can't reference DLLs in the GAC using NAnt (that I know of), you need to have the physical DLL somewhere (e.g. in your project lib folder) and reference it like a normal DLL:

<include name="lib\System\System.ComponentModel.DataAnnotations.dll"/>

One way to grab a copy of a GAC DLL is to cd to C:\Windows\assembly\GAC_MSIL from a command prompt, and list the contents with dir. This is a hidden GAC directory. If you find the assembly you need, cd into that, and you will find folders for different .NET versions (e.g. 3.5.0.0). cd into the right one and you should find the DLL itself which you can copy out. On my computer I found it at:

C:\Windows\assembly\GAC_MSIL\System.ComponentModel.DataAnnotations\3.5.0.0__31bf3856ad364e35

I think if you use MSBuild instead of csc you don't need hard references to GACed DLLs, it will find them for you.

James Allen
Really? Nant cant access the GAC?
Dan
This is maybe a good thing, it makes your code more portable - you can't guarantee who has what in their GAC. A colleague might not have System.ComponentModel.DataAnnotations, in which case he/she is screwed.
James Allen
Don't think that argument applies to system dlls.
Dan
A: 

I've never had any issues with NAnt referencing DLLs from the GAC. Your line should work, I would actually think there is likely something else wrong with your build file, but I'm just guessing.

Here's lines from one of my build files that work just fine:

<references>
    <include name="System.dll" />
    <include name="System.Data.dll" />
    <include name="System.XML.dll" />
</references>

One of th common mistakes I typically make is with my and assuming NAnt is using the project imports that are defined in the project file.

Can you tell us specifically what error you get during the compile? or if you are getting an error at runtime, what is it?

Purple Ant