Renamed Attribute to Attrib to avoid System.Attribute conflict.
[castle.git] / common-project.xml
blob9258a47aea90dc544ebaa36fae5d6126c5cea1d4
1 <?xml version="1.0" ?>
2 <project name="Castle" xmlns="http://nant.sf.net/release/0.85/nant.xsd">
4         <description>
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.
10                 Usage
12                 &lt;property name="root.dir" value="../.." /&gt;
13                 &lt;include buildfile="${root.dir}/build-common/common-project.xml" /&gt;
15                 These lines should be placed at the top level under the &lt;project&gt;
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
23                 in this file.
25                 Other predefined targets are:
27                         - common.compile-tests
28                                 compile NUnit tests and copy App.config file to the output directory,
29                                 if it exists.
31                         - common.compile-dll
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.
38                         - common.run-tests
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.
46         </description>
48         <include buildfile="common.xml" />
50         <target name="common.build">
52                 <nant>
53                         <buildfiles refid="buildfiles.all" />
54                 </nant>
56         </target>
58         <target name="common.compile-tests"
59                 description="Compile NUnit tests and copy App.config file to the output directory, if it exists.">
61                 <call target="common.compile-dll" />
63                 <!-- Check if there is a framework specific config file and use that -->
64                 <property name="app.config.src" value="${src.dir}/App-${framework::get-target-framework()}.config" />
65                 <if test="${file::exists(app.config.src)}">
66                         <copy 
67                                 file="${app.config.src}"
68                                 tofile="${build.dir}/${project::get-name()}.dll.config"
69                         />
71                         <call target="common.configure-tests" />
72                         <property name="app.config.src.found" value="true" />
73                 </if>
74                 <!-- In case there was no framework specific config check if there is a framework neutral file and use that. -->
75                 <property name="app.config.src" value="${src.dir}/App.config" />
76                 <if test="${file::exists(app.config.src)}" unless="${property::exists('app.config.src.found')}">
77                         <copy 
78                                 file="${app.config.src}"
79                                 tofile="${build.dir}/${project::get-name()}.dll.config"
80                         />
82                         <call target="common.configure-tests" />
83                 </if>
85         </target>
87         <target name="common.configure-tests"
88                 description="Configure tests for running NUnit tests.">
90                 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
92                 <!-- make sure the config file is writable -->
93                 <attrib file="${app.config}" readonly="false" />
94                 
95                 <xmlpoke
96                         file="${app.config}"
97                         xpath="/configuration/appSettings/add[@key='tests.src']/@value"
98                         value="${src.dir}"
99                         failonerror="false"
100                 />
101         </target>
103         <target name="common.compile-dll"
104                 description="Compile sources into a DLL">
106                 <if test="${build.msbuild}">
107                         <property name="msbuildlogger" value="" overwrite="false" unless="${property::exists('CCNetLabel')}" />
108                         <property name="msbuildlogger" value="/logger:ThoughtWorks.CruiseControl.MsBuild.XmlLogger" overwrite="false" if="${property::exists('CCNetLabel')}" />
109                         <property name="msbuild.defines" value="${string::replace(current.build.defines, ',', ';')}" />
111                         <exec program="${framework::get-framework-directory(framework::get-target-framework())}/MSBuild.exe" workingdir="${build.dir}">
112                                 <arg file="${src.dir}/${project.vsproj}" />
113                                 <arg value="/p:Configuration=${project.config}" />
114                                 <arg value="/p:OutputPath=${build.dir}" />
115                                 <arg value="/p:TreatWarningsAsErrors=${build.warnaserrors}" />
116                                 <arg value='/p:DefineConstants="${msbuild.defines}"' />
117                                 <arg value='/t:Rebuild' if="${build.rebuild}" />
118                                 <arg value="/p:DocumentationFile=${build.dir}/${project::get-name()}.xml" />
119                                 <arg value="/p:NoWarn=1591" unless="${build.warnmissingdocs}" />
120                                 <arg line="/p:SignAssembly=${assembly.sign} /p:AssemblyOriginatorKeyFile=${key.file}" />
121                                 <arg value="${msbuildlogger}" />
122                         </exec>
123                 </if>
124                 
125                 <if test="${not build.msbuild}">
126                         <property name="warnaserror" value="${build.warnaserrors}" />
127                         <csc
128                                 target="library" 
129                                 define="${current.build.defines}" 
130                                 debug="${build.debug}" 
131                                 optimize="${build.optimize}"
132                                 warnaserror="${warnaserror}"
133                                 output="${build.dir}/${project::get-name()}.dll" 
134                                 doc="${build.dir}/${project::get-name()}.xml"
135                                 rebuild="${build.rebuild}"
136                                 unless="${build.msbuild}"
137                         >
138                                 <nowarn>
139                                         <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
140                                 </nowarn>
141                                 <sources refid="project.sources" />
142                                 <references refid="project.references" />
143                                 <resources refid="project.resources" />
144                                 <arg line="${csc.keyfile}" if="${assembly.sign}" />
145                                 <arg line="${csc.args}" />
146                         </csc>
147                 </if>
148         </target>
150         <target name="common.compile-website">
151                 <property name="bin.dir" value="${src.dir}/bin" />
152                 <mkdir dir="${bin.dir}" />
153                 <delete file="${bin.dir}/${project::get-name()}.pdb" failonerror="false" /> <!-- To prevent 1.1 compiler from crashing when switching from a 2.0 build -->
154                 <property name="build.dir" value="${bin.dir}" />
156                 <call target="common.compile-dll" />
157                 <call target="common.copy-references" />
158         </target>
160         <target name="common.copy-references">
161                 <foreach item="File" property="reference">
162                         <in>
163                                 <items refid="project.references" />
164                         </in>
165                         <do>
166                                 <copy file="${reference}" todir="${bin.dir}" overwrite="${build.rebuild}" />
167                         </do>
168                 </foreach>
169         </target>
171         <target name="common.compile-exe"
172                 description="Compile sources into a console executable">
174                 <csc
175                         target="exe"
176                         define="${current.build.defines}" 
177                         debug="${build.debug}"
178                         optimize="${build.optimize}"
179                         warnaserror="${build.warnaserrors}"
180                         output="${build.dir}/${project::get-name()}.exe" 
181                 >
182                         <nowarn>
183                                 <warning number="1591" unless="${build.warnmissingdocs}" /> <!-- No XML comment for publicly visible member -->
184                         </nowarn>
185                         <sources refid="project.sources" />
186                         <references refid="project.references" />
187                         <resources refid="project.resources" />
188                         <arg line="${csc.keyfile}" if="${assembly.sign}" />
189                         <arg line="${csc.args}" />
190                 </csc>
191         </target>
193         <target name="common.set-assembly-attribute-values">
194                 <property overwrite="false" name="assembly.is-cls-compliant" value="true" />
195                 <property overwrite="false" name="assembly.is-com-visible" value="false" />
196                 <property overwrite="false" name="assembly.guid" value="" />
197                 <property overwrite="false" name="assembly.allow-partially-trusted-callers" value="false" />
198                 <property overwrite="false" name="assembly.description" value="" />
199                 <property overwrite="false" name="assembly.product" value="${project::get-name()}" />
200                 <property overwrite="false" name="assembly.company" value="${project.company}" />
201                 <property overwrite="false" name="assembly.title" value="${project::get-name()} for ${framework::get-description(framework::get-target-framework())}" />
202                 <property overwrite="false" name="assembly.version" value="${project.major}.${project.minor}.${project.build}.0" />
203                 <property overwrite="false" name="assembly.version.informational" value="${assembly.major}.${assembly.minor}.${assembly.build}.${svn.revision}" />
204                 <property overwrite="false" name="assembly.copyright" value="Castle Project, original author or authors" />
205                 <property overwrite="false" name="assembly.keyfile" value="${key.file}" />
206                 <property overwrite="false" name="assembly.sign" value="${sign}" />
207         </target>
209         <target name="common.generate-assemblyinfo"
210                 depends="common.init common.set-assembly-attribute-values"
211                 description="Generate AssemblyInfo.cs using assembly.* properties."
212         >
213                 <property name="assemblyinfo.cs" value="${path::combine(src.dir,'AssemblyInfo.cs')}" />
214                 <attrib file="${assemblyinfo.cs}" readonly="false" />
215                 <asminfo output="${assemblyinfo.cs}" language="CSharp">
216                         <imports>
217                                 <import namespace="System" />
218                                 <import namespace="System.Reflection" />
219                                 <import namespace="System.Runtime.CompilerServices" />
220                                 <import namespace="System.Runtime.InteropServices" />
221                                 <import namespace="System.Security" if="${assembly.allow-partially-trusted-callers}" />
222                         </imports>
223                         <attributes>
224                                 <attribute type="CLSCompliantAttribute" value="${assembly.is-cls-compliant}" />
225                                 <attribute type="ComVisibleAttribute" value="${assembly.is-com-visible}" />
226                                 <attribute type="GuidAttribute" value="${assembly.guid}" if="${assembly.guid != ''}" />
227                                 <attribute type="AssemblyTitleAttribute" value="${assembly.title}" />
228                                 <attribute type="AssemblyDescriptionAttribute" value="${assembly.description}" />
229                                 <attribute type="AssemblyCompanyAttribute" value="${assembly.company}" />
230                                 <attribute type="AssemblyProductAttribute" value="${assembly.product}" />
231                                 <attribute type="AssemblyCopyrightAttribute" value="${assembly.copyright}" />
232                                 <attribute type="AssemblyVersionAttribute" value="${assembly.version}" />
233                                 <attribute type="AssemblyInformationalVersionAttribute" value="${assembly.version.informational}" />
234                                 <attribute type="AssemblyFileVersionAttribute" value="${assembly.version.informational}" />
235                                 <attribute type="AssemblyDelaySignAttribute" value="false" />
236                                 
237                                 <!-- For some reason, NAnt doesn't detect that APTCA has a public no-argument constructor -->
238                                 <attribute asis="true" type="AllowPartiallyTrustedCallersAttribute" if="${assembly.allow-partially-trusted-callers}" />
239                         </attributes>
240                 </asminfo>
241                 <if test="${assembly.sign and not (nant.settings.currentframework == 'net-2.0')}" >
242                         <echo append="true" file="${assemblyinfo.cs}">#if MONO</echo>
243                         <echo append="true" file="${assemblyinfo.cs}">[assembly: AssemblyKeyFileAttribute(@"${path::get-full-path(assembly.keyfile)}")]</echo>
244                         <echo append="true" file="${assemblyinfo.cs}">#endif</echo>
245                 </if>
246         </target>
247         
248         <target name="common.assemblyinfo">
250                 <nant target="generate-assemblyinfo">
251                         <buildfiles refid="buildfiles.all" />
252                 </nant>
254         </target>
256         <target name="common.run-tests"
257                 description="Run NUnit tests">
259                 <if test="${common.testrunner.enabled}">
260                         <call target="common.find-nunit" unless="${property::exists('nunit.found')}" />
262                         <echo message="Running tests in '${project::get-name()}'" />
264                         <exec if="${mbunit.found and string::to-lower(testrunner)=='mbunit'}"
265                                 program="${mbunit-console}" 
266                                 workingdir="${build.dir}"
267                                 commandline="${project::get-name()}.dll /rf:${testresults.dir} /rnf:${project::get-name()}.dll-results /rt:Xml"
268                                 failonerror="${common.testrunner.failonerror}"
269                         />
270                         <!-- Use nunit-console.exe if found, otherwise fall back to nunit2 task -->
271                         <exec if="${nunit.found and string::to-lower(testrunner)=='nunit'}"
272                                 program="${nunit-console}" 
273                                 workingdir="${build.dir}" 
274                                 commandline="${project::get-name()}.dll /xml:${testresults.dir}/${project::get-name()}.dll-results.xml /config:${build.dir}/${project::get-name()}.dll.config /nologo"
275                                 failonerror="${common.testrunner.failonerror}"
276                         />
277                 </if>
278                 <if test="${not common.testrunner.enabled}">
279                         <echo message="Tests are disabled for '${project::get-name()}'" />
280                 </if>
282         </target>
284         <target name="common.run-database-tests"
285                 depends="common.put-connection-settings-into-app-config common.run-tests common.remove-connection-settings-from-app-config" />
287         <target name="common.put-connection-settings-into-app-config">
289                 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
291                 <!-- make sure the config file is writable -->
292                 <attrib file="${app.config}" readonly="false" />
294                 <!-- 
295                         Tell nhibernate how to connect to the test database.
296                 -->
297                 <xmlpoke
298                         file="${app.config}"
299                         xpath="/configuration/nhibernate/add[@key='hibernate.dialect']/@value"
300                         value="${nhibernate.dialect}" 
301                 />
302                 <xmlpoke
303                         file="${app.config}"
304                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.driver_class']/@value"
305                         value="${nhibernate.connection.driver_class}" 
306                 />
307                 <xmlpoke
308                         file="${app.config}"
309                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
310                         value="${nhibernate.connection.connection_string}" 
311                 />
312         </target>
314         <target name="common.remove-connection-settings-from-app-config">
315                 <property name="app.config" value="${build.dir}/${project::get-name()}.dll.config" />
317                 <xmlpoke
318                         file="${app.config}"
319                         xpath="/configuration/nhibernate/add[@key='hibernate.connection.connection_string']/@value"
320                         value="conn string here" 
321                 />
322         </target>
324 </project>