2 <project name="Castle" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
5 This file contains common tasks tailored specifically for the Castle
6 build process. The goal was to define all the actions in this file, so
7 that actual project build files only have to configure a few variables
8 and call tasks in this file.
12 <property name="root.dir" value="../.." />
13 <include buildfile="${root.dir}/build-common/common-project.xml" />
15 These lines should be placed at the top level under the <project>
16 element. Property root.dir defines a relative path to the root of the
17 distribution, that is, Castle directory.
19 After including the file, a target should be defined to initialize
20 configuration variables according to the project being built.
21 The standard of this target is init (but any other name can be chosen).
22 The init target should depend on (or call) target common.init defined
25 Other predefined targets are:
27 - common.compile-tests
28 compile NUnit tests and copy App.config file to the output directory,
32 compile a DLL, generating the documentation and using Clover if enabled.
34 - common.generate-assemblyinfo, common.generate-assemblyinfoversion
35 generate an AssemblyInfo.cs or AssemblyInfoVersion.cs file from
36 assembly.* NAnt properties.
39 run compiled NUnit tests.
41 All compile/run targets put the output in build.dir. Common.compile*
42 targets use source fileset with id="project.sources", assembly fileset
43 with id="project.references" and resource fileset with id="project.resources"
44 to compile the project. The source and resource filesets are optional.
48 <include buildfile="common.xml" />
50 <target name="common.build">
53 <buildfiles refid="buildfiles.all" />
58 <target name="common.compile-tests"
59 description="Compile NUnit tests and copy App.config file to the output directory, if it exists.">
61 <property name="istestsproject" value="true" />
62 <call target="common.compile-dll" />
64 <!-- Check if there is a framework specific config file and use that -->
65 <property name="app.config.src" value="${src.dir}/App-${framework::get-target-framework()}.config" />
66 <if test="${file::exists(app.config.src)}">
68 file="${app.config.src}"
69 tofile="${build.dir}/${project::get-name()}.dll.config"
72 <call target="common.configure-tests" />
73 <property name="app.config.src.found" value="true" />
75 <!-- In case there was no framework specific config check if there is a framework neutral file and use that. -->
76 <property name="app.config.src" value="${src.dir}/App.config" />
77 <if test="${file::exists(app.config.src)}" unless="${property::exists('app.config.src.found')}">
79 file="${app.config.src}"
80 tofile="${build.dir}/${project::get-name()}.dll.config"
83 <call target="common.configure-tests" />
88 <target name="common.configure-tests"
89 description="Configure tests for running NUnit tests.">
91 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
93 <!-- make sure the config file is writable -->
94 <attrib file="${app.config}" readonly="false" />
98 xpath="/configuration/appSettings/add[@key='tests.src']/@value"
104 <target name="common.compile-dll"
105 description="Compile sources into a DLL">
107 <property name="istestsproject" value="false" overwrite="false" />
109 <if test="${build.msbuild}">
110 <property name="msbuildlogger" value="" overwrite="false" unless="${property::exists('CCNetLabel')}" />
111 <property name="msbuildlogger" value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger" overwrite="false" if="${property::exists('CCNetLabel')}" />
112 <property name="msbuild.defines" value="${string::replace(current.build.defines, ',', ';')}" />
114 <exec program="${framework::get-framework-directory(framework::get-target-framework())}/MSBuild.exe" workingdir="${build.dir}">
115 <arg file="${src.dir}/${project.vsproj}" />
116 <arg value="/p:Configuration=${project.config}" />
117 <arg value="/p:OutputPath=${build.dir}" />
118 <arg value="/p:TreatWarningsAsErrors=${build.warnaserrors}" unless="${istestsproject}" />
119 <arg value='/p:DefineConstants="${msbuild.defines}"' />
120 <arg value='/t:Rebuild' if="${build.rebuild}" />
121 <arg value="/p:DocumentationFile=${build.dir}/${project::get-name()}.xml" unless="${istestsproject}" />
122 <arg value="/p:NoWarn=1591" unless="${build.warnmissingdocs}" />
123 <arg line="/p:SignAssembly=${assembly.sign} /p:AssemblyOriginatorKeyFile=${key.file}" />
124 <arg value="${msbuildlogger}" />
128 <if test="${not build.msbuild}">
129 <property name="warnaserror" value="false" if="${istestsproject}" />
130 <property name="warnaserror" value="${build.warnaserrors}" if="${not istestsproject}" />
133 define="${current.build.defines}"
134 debug="${build.debug}"
135 optimize="${build.optimize}"
136 warnaserror="${warnaserror}"
137 output="${build.dir}/${project::get-name()}.dll"
138 doc="${build.dir}/${project::get-name()}.xml"
139 rebuild="${build.rebuild}"
140 unless="${build.msbuild}"
143 <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
145 <sources refid="project.sources" />
146 <references refid="project.references" />
147 <resources refid="project.resources" />
148 <arg line="${csc.keyfile}" if="${assembly.sign}" />
149 <arg line="${csc.args}" />
154 <target name="common.compile-website">
155 <property name="bin.dir" value="${src.dir}/bin" />
156 <mkdir dir="${bin.dir}" />
157 <delete file="${bin.dir}/${project::get-name()}.pdb" failonerror="false" /> <!-- To prevent 1.1 compiler from crashing when switching from a 2.0 build -->
158 <property name="build.dir" value="${bin.dir}" />
160 <call target="common.compile-dll" />
161 <call target="common.copy-references" />
164 <target name="common.copy-references">
165 <foreach item="File" property="reference">
167 <items refid="project.references" />
170 <copy file="${reference}" todir="${bin.dir}" overwrite="${build.rebuild}" />
175 <target name="common.compile-exe"
176 description="Compile sources into a console executable">
180 define="${current.build.defines}"
181 debug="${build.debug}"
182 optimize="${build.optimize}"
183 warnaserror="${build.warnaserrors}"
184 output="${build.dir}/${project::get-name()}.exe"
187 <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
189 <sources refid="project.sources" />
190 <references refid="project.references" />
191 <resources refid="project.resources" />
192 <arg line="${csc.keyfile}" if="${assembly.sign}" />
193 <arg line="${csc.args}" />
197 <target name="common.set-assembly-attribute-values">
198 <property overwrite="false" name="assembly.is-cls-compliant" value="true" />
199 <property overwrite="false" name="assembly.is-com-visible" value="false" />
200 <property overwrite="false" name="assembly.guid" value="" />
201 <property overwrite="false" name="assembly.allow-partially-trusted-callers" value="false" />
202 <property overwrite="false" name="assembly.description" value="" />
203 <property overwrite="false" name="assembly.product" value="${project::get-name()}" />
204 <property overwrite="false" name="assembly.company" value="${project.company}" />
205 <property overwrite="false" name="assembly.title" value="${project::get-name()} for ${framework::get-description(framework::get-target-framework())}" />
206 <property overwrite="false" name="assembly.version" value="${project.major}.${project.minor}.${project.build}.0" />
207 <property overwrite="false" name="assembly.version.informational" value="${assembly.major}.${assembly.minor}.${assembly.build}.${svn.revision}" />
208 <property overwrite="false" name="assembly.copyright" value="Castle Project, original author or authors" />
209 <property overwrite="false" name="assembly.keyfile" value="${key.file}" />
210 <property overwrite="false" name="assembly.sign" value="${sign}" />
213 <target name="common.generate-assemblyinfo"
214 depends="common.init common.set-assembly-attribute-values"
215 description="Generate AssemblyInfo.cs using assembly.* properties."
217 <property name="assemblyinfo.cs" value="${path::combine(src.dir,'AssemblyInfo.cs')}" />
218 <attrib file="${assemblyinfo.cs}" readonly="false" />
219 <asminfo output="${assemblyinfo.cs}" language="CSharp">
221 <import namespace="System" />
222 <import namespace="System.Reflection" />
223 <import namespace="System.Runtime.CompilerServices" />
224 <import namespace="System.Runtime.InteropServices" />
225 <import namespace="System.Security" if="${assembly.allow-partially-trusted-callers}" />
228 <attribute type="CLSCompliantAttribute" value="${assembly.is-cls-compliant}" />
229 <attribute type="ComVisibleAttribute" value="${assembly.is-com-visible}" />
230 <attribute type="GuidAttribute" value="${assembly.guid}" if="${assembly.guid != ''}" />
231 <attribute type="AssemblyTitleAttribute" value="${assembly.title}" />
232 <attribute type="AssemblyDescriptionAttribute" value="${assembly.description}" />
233 <attribute type="AssemblyCompanyAttribute" value="${assembly.company}" />
234 <attribute type="AssemblyProductAttribute" value="${assembly.product}" />
235 <attribute type="AssemblyCopyrightAttribute" value="${assembly.copyright}" />
236 <attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
237 <attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version.informational}" />
238 <attribute type="AssemblyFileVersionAttribute" value="${assembly.version.informational}" />
239 <attribute type="AssemblyDelaySignAttribute" value="false" />
241 <!-- For some reason, NAnt doesn't detect that APTCA has a public no-argument constructor -->
242 <attribute asis="true" type="AllowPartiallyTrustedCallersAttribute" if="${assembly.allow-partially-trusted-callers}" />
245 <if test="${assembly.sign}" >
246 <echo append="true" file="${assemblyinfo.cs}">#if !DOTNET2 || MONO</echo>
247 <echo append="true" file="${assemblyinfo.cs}">[assembly: AssemblyKeyFileAttribute(@"${path::get-full-path(assembly.keyfile)}")]</echo>
248 <echo append="true" file="${assemblyinfo.cs}">#endif</echo>
252 <target name="common.assemblyinfo">
254 <nant target="generate-assemblyinfo">
255 <buildfiles refid="buildfiles.all" />
260 <target name="common.run-tests"
261 description="Run NUnit tests">
263 <if test="${common.testrunner.enabled}">
264 <call target="common.find-nunit" />
266 <echo message="Running tests in '${project::get-name()}'" />
268 <exec if="${mbunit.found and string::to-lower(testrunner)=='mbunit'}"
269 program="${mbunit-console}"
270 workingdir="${build.dir}"
271 commandline="${project::get-name()}.dll /rf:${testresults.dir} /rnf:${project::get-name()}.dll-results /rt:Xml"
272 failonerror="${common.testrunner.failonerror}"
274 <!-- Use nunit-console.exe if found, otherwise fall back to nunit2 task -->
275 <exec if="${nunit.found and string::to-lower(testrunner)=='nunit'}"
276 program="${nunit-console}"
277 workingdir="${build.dir}"
278 commandline="${project::get-name()}.dll /xml:${testresults.dir}/${project::get-name()}.dll-results.xml /config:${build.dir}/${project::get-name()}.dll.config /nologo"
279 failonerror="${common.testrunner.failonerror}"
282 <nunit2 unless="${nunit.found}" if="${string::to-lower(testrunner)=='nunit'}" failonerror="${common.testrunner.failonerror}">
287 outputdir="${testresults.dir}"
290 assemblyname="${build.dir}/${project::get-name()}.dll"
291 appconfig="${build.dir}/${project::get-name()}.dll.config" />
294 <if test="${not common.testrunner.enabled}">
295 <echo message="Tests are disabled for '${project::get-name()}'" />
300 <target name="common.run-database-tests"
301 depends="common.put-connection-settings-into-app-config common.run-tests common.remove-connection-settings-from-app-config" />
303 <target name="common.put-connection-settings-into-app-config">
305 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
307 <!-- make sure the config file is writable -->
308 <attrib file="${app.config}" readonly="false" />
311 Tell nhibernate how to connect to the test database.
315 xpath="/configuration/nhibernate/add[@key='hibernate.dialect']/@value"
316 value="${nhibernate.dialect}"
320 xpath="/configuration/nhibernate/add[@key='hibernate.connection.driver_class']/@value"
321 value="${nhibernate.connection.driver_class}"
325 xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
326 value="${nhibernate.connection.connection_string}"
330 <target name="common.remove-connection-settings-from-app-config">
331 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
335 xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
336 value="conn string here"