How to build a class library using Nant

How can I compile .net 3.5 class library in dll using Nant (0.86)?

This is what I have so far:

How do I access the system DLL in the GAC? This line seems 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 using JP Boodhoos post

+4
source share
3 answers

You cannot reference the DLLs in the GAC using NAnt (which I know), you need to have a physical DLL somewhere (for example, in the lib project folder) and refer to it as a regular DLL:

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

One way to grab a copy of the GAC DLL is to cd in C: \ Windows \ assembly \ GAC_MSIL from the command line and list the contents with dir. This is the hidden GAC directory. If you find the assembly you need, cd, and you will find folders for different versions of .NET (for example, 3.5.0.0). cd is in the correct order, and you should find the very dll that you can copy. On my computer, I found it at:

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

I think that if you use MSBuild instead of csc, you do not need hard links to the GACed DLL, it will find them for you.

+4
source

@Dan

If you please list which version of .Net are you targeting? I am a new nAnt user, and one element that I learned pretty quickly is that the creation of Dll and executables oriented to the 3.5SP1 structure should be done using the 0.86 beta bit instead of the 0.85 version you are in.

You can use 0.85, but then you need to turn to the MSBuild tasks and go to the solution / project files. It took me a day searching the Internet to understand.

+2
source

I have never had a problem with NAnt linking to DLL files from the GAC. Your line should work, I would really think that there might be something else wrong with your build file, but I just guess.

Here are the lines from one of my build files that work very well:

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

One of the common mistakes that I usually make is related to mine and suggests that NAnt uses import of projects that are defined in the project file.

Can you tell us what error you get during compilation? or if you get a runtime error, what is it?

0
source

Source: https://habr.com/ru/post/1286183/


All Articles