NAnt provides a CSC task that will allow you to compile your C# project (sorry, VB guys, no info for you :)). It may be used this way:
<!-- 2. Building shared data project -->
<csc target="library" debug="false" warnaserror="true"
<include name="**/*.cs" />
<include name="D:/projects/MyProject/External/NHibernate.dll" />
<warning number="1702" />
So let's have a look in details at each part of this task.Attributes
One by one:
- target="library" - indicates that we want to have a .dll as result of our compilation. Possible values are
- debug="false" - indicates that no debug symbols will be included into our assembly. Possible values are
PdbOnly. Although you can use aliases (like I did):
- warnaserror="true" - has same effect like checking 'Treat warnings as errors - All' option in Visual Studio. All warnings will be treated as errors.
- output="D:/projects/MyProject/Integration/MyProject.dll" - output of compilation. Make sure your output target extension is adequate to your compilation target (although I haven't tried compiling target library to output .exe :-P)
This nested element allows you to select files that should be compiled. It's only attribute I use here is:
basedir="D:/projects/MyProject/Source" - base directory for source files. Usually this is root folder for some project.
The <include> element allows you to specify elements that should be compiled. It's attribute, name, deserves some attention. First, it uses wildcards to pick necessary items. Second, it uses double asterisk to recursively pick all files from all folders. Have a look:
- name="*.cs" will pick .cs files only in current folder
- name="**/*.cs" will pick .cs files from current folder and from all subfolders, their subfolders, etc.
This nested element allows you to specify assemblies that should be references. Syntax also supports wildcards so you can easily specify *.dll to reference all .dll files in some folder.
This element allows you to deal with resources embedded into your assembly. In this particular case I use this element to embed NHibernate .hbm mappings.Nowarn
This section allows you to ignore some specific warnings via nested <warning /> element. Use it's number="1702" attribute to specify some specific warning you want to ignore.
That's a short explanation on CSC target, more information can be found here. Hope this post will be helpful to anyone other than myself :D