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"
output="D:/projects/MyProject/Integration/MyProject.dll">
<sources basedir="D:/projects/MyProject/Source">
<include name="**/*.cs" />
</sources>
<references>
<include name="D:/projects/MyProject/External/NHibernate.dll" />
</references>
<resources>
<include name="D:/projects/MyProject/Source/NHib/*.hbm.xml"/>
</resources>
<nowarn>
<warning number="1702" />
</nowarn>
</csc>
So let's have a look in details at each part of this task.
AttributesOne by one:
- target="library" - indicates that we want to have a .dll as result of our compilation. Possible values are
exe
,winexe
,library
ormodule
. - debug="false" - indicates that no debug symbols will be included into our assembly. Possible values are
Enable
,Full
,None
andPdbOnly
. Although you can use aliases (like I did):true
stands forEnable
andfalse
stands forNone.
- 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.
References
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.
Resources
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.
NowarnThis 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.
Conclusion
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
No comments:
Post a Comment