You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

dotnet.html 15 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473
  1. <html>
  2. <head>
  3. <title> .NET classes for Ant
  4. </title>
  5. </head>
  6. <body bgcolor="#ffffff">
  7. <h1>.NET classes for Ant</h1>
  8. <p>By Steve Loughran; steve_l@iseran.com</p>
  9. <h2>Vision</h2>
  10. <p>
  11. Make ant the definitive build tool for .NET projects, just
  12. as it is becoming for java projects
  13. </p>
  14. <h2>Detail</h2>
  15. <p>
  16. The emergent policy in big java projects is 'IDE for code and debug';
  17. Ant for builds, test and deployment. While IDEs are great for an
  18. individual development task, Ant not only rebuilds everything insanely
  19. fast, it has great support for modern deployment tasks -ftp upload,
  20. EJB servers, SQL commands, all can be done from a relatively simple
  21. XML declaration of what you want done. Also in a large project
  22. (especially open source) there is no means of dictating which IDE to use.
  23. Ant gives IDE independence, cross platform portability and ease of
  24. extensibility. </p>
  25. <p>
  26. Projects using .net should be able to use the same tool. This will
  27. avoid everyone being dependent on Visual Studio.net (if they have it)
  28. supplemented with makefiles and batch files. Anyone doing mixed java/dotnet
  29. development will be particulary grateful, as they can have a unified build
  30. process. </p>
  31. <p>
  32. If at sometime in the future bits of .net do appear on different platforms
  33. then ant based build files will migrate -once the ant tasks have been
  34. migrated and any hard codings of DOS-descendant file system conventions
  35. removed from the build.xml files.</p>
  36. <h2>Key .net Tasks</h2>
  37. <ol>
  38. <li>csc - csharp compiler - *.csc -&gt; output</li>
  39. <li>ilasm - IL assembler - *.il -&gt;.exe or .dll</li>
  40. <li>ResX - ResXToResources.exe .resx -&gt; .resources</li>
  41. <li>al - assembly linker (.dll) -&gt;</li>
  42. <li>Signcode - .exe + keys -&gt; .exe</li>
  43. <li>Resgen - .properties -&gt; .resources</li>
  44. <li>Type Library Exporter (TlbExp.exe) .dll -&gt; .tlb</li>
  45. <li>TlbImp.exe Type Library Importer </li>
  46. <li>RegAsm.exe Assembly Registration Tool .dll -&gt; .reg | registration</li>
  47. <li>WebServiceUtil -SOAP proxy import, SDL generation tool</li>
  48. </ol>
  49. <h2>Ant Wrapper for net tasks</h2>
  50. Rarely used .net command line tools can be invoked manually. The key tasks
  51. to address are the common steps in a build process and those which benefit
  52. from the file pattern matching function.
  53. <p>
  54. The esoteric tasks can then supported on demand by those who need them.
  55. The initial .net tasks should provide a foundation for that demand creation
  56. to be simple. </p>
  57. <h2>Plan</h2>
  58. <ol>
  59. <li>code up C sharp task and distribute for feedback &amp; identify possible
  60. aid</li>
  61. <li>Use for a real end to end development task</li>
  62. <li>Add the next task I need (whatever that is)</li>
  63. <li>Refactor to produce a base class for .net tasks</li>
  64. <li>Leave it other people write all the other tasks</li>
  65. </ol>
  66. <h2>Risks</h2>
  67. <ul>
  68. <li>
  69. The .net SDK is unstable; the next builds will change the commands, arguments
  70. and behaviours. Probability: 100%. Impact: 2 days.</li>
  71. <li>Portable tasks turn out to be harder than envisaged
  72. (=reworking if/when non Win32 .net build tools appear)</li>
  73. </ul>
  74. <hr>
  75. <h2>Using Ant in .net projects</h2>
  76. To use the net tasks one needs
  77. <ul>
  78. <li> A Win2K box (or any other platform which supports the .net build tools)</li>
  79. <li> JavaVM - Java1.1 or later; Java1.3 recommended.</li>
  80. <li> Ant downloaded and the environment and path variables set up so
  81. that typing 'ant' invokes ant via a batch file.</li>
  82. <li> An XML parser for ant. The usual distributions include an appropriate
  83. version crimson.jar and jaxp.jar.</li>
  84. <li> the .net tasks archive (dotnettasks.jar) included in the
  85. ant\lib directory</li>
  86. <li> The .net sdk installed with the binaries on the path. (Test: type CSC)</li>
  87. <li> A build.xml file to describe the build process</li>
  88. </ul>
  89. <hr>
  90. <h2> Change Log </h2>
  91. <h4>Version 0.3</h4>
  92. The changes here reflect Beta-1 of the dotnet SDK and experience of use in
  93. more complex projects. This build does not work with the older SDK,
  94. primarily because the automatic reference feature references libraries
  95. only found in the new SDK version.
  96. <p>
  97. External changes</p>
  98. <ul>
  99. <li>Recursive inclusion of .cs and .il files</li>
  100. <li>Documentation enhanced, includes examples and details of all parameters</li>
  101. <li>The csc task automatically includes the common dotnet assemblies, so
  102. there is no need to remember to refer to 'System.dll', 'System.Web.Services',
  103. etc. This feature can be disabled by setting the 'includeDefaultReferences'
  104. flag to false. </li>
  105. <li> References can also be referred to using the ReferenceFiles parameter, which
  106. is an ant path specification. The old 'references' string is still retained.</li>
  107. <li> An 'extraoptions' attribute enables the build file to include any CSC options
  108. which are not explicitly supported in the CSC task. </li>
  109. </ul>
  110. Internal changes
  111. <ul>
  112. <li>Some minor refactoring (move common code a method)</li>
  113. <li>Application of Jedits JavaStyle task resulted in a major reshaping of
  114. the codebase and the insertion of a blank line every second line. Significant
  115. effort was required to revert some (but not all) changes.</li>
  116. <li>Removed throws clause from methods which can't throw exceptions </li>
  117. </ul>
  118. The test harness has been expanded to include unicode source file
  119. (the build works but the rest of the system has 'issues' with high unicode
  120. package and method names)
  121. <h4>Version 0.2</h4>
  122. First public edition, added to the ant cvs tree. Tested on the PDC build of
  123. the dotnet SDK only, and still immature. The command execution code was
  124. refactored out into a 'NetCommand' class for re-use. The Ilasm task was added
  125. at this time.
  126. <h4>Version 0.1</h4>
  127. Initial proof of concept; very rudimentary support for CSC only.
  128. <hr>
  129. <h2>Task: CSC</h2>
  130. This task compiles CSharp source into executables or modules.
  131. This task compiles CSharp source into executables or modules.
  132. The task will only work on win2K until other platforms support csc.exe or
  133. an equivalent. CSC.exe must be on the execute path too.
  134. <p>
  135. All parameters are optional: &lt;csc/&gt; should suffice to produce a debug
  136. build of all *.cs files. References to external files do require explicit
  137. enumeration, so are one of the first attributes to consider adding. </p>
  138. <p>
  139. The task is a directory based task, so attributes like <b>includes=&quot;**/*.cs&quot;</b> and
  140. <b>excludes=&quot;broken.cs&quot;</b> can be used to control the files pulled in. By default,
  141. all *.cs files from the project folder down are included in the command.
  142. When this happens the output file -if not specified-
  143. is taken as the first file in the list, which may be somewhat hard to control.
  144. Specifying the output file with <b>'outfile'</b> seems prudent. </p>
  145. <table border="1" cellpadding="2" cellspacing="0">
  146. <tr>
  147. <td valign="top"><b>Attribute</b></td>
  148. <td valign="top"><b>Description</b></td>
  149. <td align="center" valign="top"><b>Example Values</b></td>
  150. </tr>
  151. <tr>
  152. <td valign="top">additionalModules</td>
  153. <td valign="top">Semicolon separated list of modules to refer to</td>
  154. </tr>
  155. <tr>
  156. <td valign="top">defaultexcludes</td>
  157. <td valign="top">indicates whether default excludes should be used or not
  158. </td>
  159. <td valign="top">&quot;true&quot;(default) or &quot;false&quot;</td>
  160. </tr>
  161. <tr>
  162. <td valign="top">definitions</td>
  163. <td valign="top">defined constants</td>
  164. <td valign="top"> &quot;RELEASE;BETA1&quot;</td>
  165. </tr>
  166. <tr>
  167. <td valign="top">debug</td>
  168. <td valign="top">include debug information</td>
  169. <td valign="top">&quot;true&quot;(default) or &quot;false&quot;</td>
  170. </tr>
  171. <tr>
  172. <td valign="top">docFile</td>
  173. <td valign="top">name of file for documentation</td>
  174. <td valign="top">&quot;doc.xml&quot;</td>
  175. </tr>
  176. <tr>
  177. <td valign="top">excludes</td>
  178. <td valign="top">comma separated list of patterns of files that must be
  179. excluded. No files (except default excludes) are excluded when omitted.</td>
  180. </tr>
  181. <tr>
  182. <td valign="top">excludesfile</td>
  183. <td valign="top">the name of a file. Each line of this file is
  184. taken to be an exclude pattern</td>
  185. </tr>
  186. <tr>
  187. <td valign="top">extraOptions</td>
  188. <td valign="top">Any extra options which aren't explicitly
  189. supported by the CSharp task </td>
  190. <td>&quot;/warnaserror+ /baseaddress:0x12840000&quot;</td>
  191. </tr>
  192. <tr>
  193. <td valign="top">failOnError</td>
  194. <td valign="top">Should a failed compile halt the build?</td>
  195. <td valign="top">&quot;true&quot;(default) or &quot;false&quot;</td>
  196. </tr>
  197. <tr>
  198. <td valign="top">includes</td>
  199. <td valign="top">comma separated list of patterns of files that must be
  200. included. All files are included when omitted.</td>
  201. </tr>
  202. <tr>
  203. <td valign="top">includeDefaultReferences</td>
  204. <td valign="top">Flag which when true automatically includes
  205. the common assemblies in dotnet beta1, and tells the compiler to link in
  206. mscore.dll
  207. </td>
  208. <td valign="top">&quot;true&quot;(default) or &quot;false&quot;</td>
  209. </tr>
  210. <tr>
  211. <td valign="top">includesfile</td>
  212. <td valign="top">the name of a file. Each line of this file is
  213. taken to be an include pattern</td>
  214. </tr>
  215. <tr>
  216. <td valign="top">incremental</td>
  217. <td valign="top">Incremental build flag. Avoid till it works</td>
  218. <td valign="top">&quot;true&quot; or &quot;false&quot;(default)</td>
  219. </tr>
  220. <tr>
  221. <td valign="top">mainClass</td>
  222. <td valign="top">name of main class for executables</td>
  223. <td valign="top">&quot;com.example.project.entrypoint&quot;</td>
  224. </tr>
  225. <tr>
  226. <td valign="top">optimize</td>
  227. <td valign="top">optimisation flag</td>
  228. <td valign="top">&quot;true&quot; or &quot;false&quot;(default)</td>
  229. </tr>
  230. <tr>
  231. <td valign="top">outputFile</td>
  232. <td valign="top">filename of output</td>
  233. <td valign="top">&quot;example.exe&quot;</td>
  234. </tr>
  235. <tr>
  236. <td valign="top">references</td>
  237. <td valign="top">Semicolon separated list of dlls to refer to</td>
  238. <td valign="top">&quot;mylib.dll;nunit.dll&quot;</td>
  239. </tr>
  240. <tr>
  241. <td valign="top">referenceFiles </td>
  242. <td valign="top">Ant Path descriptioon of references to include.
  243. Wildcards should work. </td>
  244. <td valign="top"></td>
  245. </tr>
  246. <tr>
  247. <td valign="top">srcDir</td>
  248. <td valign="top">source directory (default = project directory)</td>
  249. <td valign="top">&quot;.&quot;</td>
  250. </tr>
  251. <tr>
  252. <td valign="top">targetType</td>
  253. <td valign="top">Type of target</td>
  254. <td valign="top">&quot;exe&quot;, &quot;module&quot;, &quot;winexe&quot; or &quot;library&quot;</td>
  255. </tr>
  256. <tr>
  257. <td valign="top">unsafe</td>
  258. <td valign="top">enable unsafe code</td>
  259. <td valign="top">&quot;true&quot; or &quot;false&quot;(default)</td>
  260. </tr>
  261. <tr>
  262. <td valign="top">warnLevel</td>
  263. <td valign="top">level of warning currently between 1 and 4 with 4
  264. being the strictest. </td>
  265. <td valign="top">&quot;1&quot;-&quot;4&quot;</td>
  266. </tr>
  267. <tr>
  268. <td valign="top">win32Icon</td>
  269. <td valign="top">filename of icon to include</td>
  270. <td valign="top">&quot;res/myicon.ico&quot;</td>
  271. </tr>
  272. </table>
  273. <p>
  274. Example
  275. </p>
  276. <pre>&lt;csc
  277. optimize=&quot;true&quot;
  278. debug=&quot;false&quot;
  279. docFile=&quot;documentation.xml&quot;
  280. warnLevel=&quot;4&quot;
  281. unsafe=&quot;false&quot;
  282. targetType=&quot;exe&quot;
  283. incremental=&quot;false&quot;
  284. definitions=&quot;RELEASE&quot;
  285. excludes=&quot;src/unicode_class.cs&quot;
  286. mainClass = &quot;MainApp&quot;
  287. outputFile=&quot;NetApp.exe&quot;
  288. /&gt;
  289. </pre>
  290. <hr>
  291. <h2> Task: ilasm </h2>
  292. <p>Task to assemble .net 'Intermediate Language' files.
  293. The task will only work on win2K until other platforms support csc.exe or
  294. an equivalent. ilasm.exe must be on the execute path too.
  295. </p>
  296. <p>
  297. All parameters are optional: &lt;il/&gt; should suffice to produce a debug
  298. build of all *.il files.
  299. The option set is roughly compatible with the CSharp class;
  300. even though the command line options are only vaguely
  301. equivalent. [The low level commands take things like /OUT=file,
  302. csc wants /out:file ... /verbose is used some places; /quiet here in
  303. ildasm... etc.] It would be nice if someone made all the command line
  304. tools consistent (and not as brittle as the java cmdline tools)
  305. </p>
  306. <p>
  307. The task is a directory based task, so attributes like <b>includes=&quot;*.il&quot;</b> and
  308. <b>excludes=&quot;broken.il&quot;</b> can be used to control the files pulled in.
  309. Each file is built on its own, producing an appropriately named output file unless
  310. manually specified with <b>outfile</b>
  311. </p>
  312. <table border="1" cellpadding="2" cellspacing="0">
  313. <tr>
  314. <td valign="top"><b>Attribute</b></td>
  315. <td valign="top"><b>Description</b></td>
  316. <td align="center" valign="top"><b>Example</b></td>
  317. </tr>
  318. <tr>
  319. <td valign="top">defaultexcludes</td>
  320. <td valign="top">indicates whether default excludes should be used or not
  321. (&quot;yes&quot;/&quot;no&quot;). Default excludes are used when omitted.</td>
  322. </tr>
  323. <tr>
  324. <td valign="top">debug</td>
  325. <td valign="top">include debug information</td>
  326. <td valign="top">true (default)</td>
  327. </tr>
  328. <tr>
  329. <td valign="top">excludes</td>
  330. <td valign="top">comma separated list of patterns of files that must be
  331. excluded. No files (except default excludes) are excluded when omitted.</td>
  332. </tr>
  333. <tr>
  334. <td valign="top">excludesfile</td>
  335. <td valign="top">the name of a file. Each line of this file is
  336. taken to be an exclude pattern</td>
  337. </tr>
  338. <tr>
  339. <td valign="top">extraOptions</td>
  340. <td valign="top">Any extra options which aren't explicitly
  341. supported by the ilasm task </td>
  342. <td></td>
  343. </tr>
  344. <tr>
  345. <td valign="top">failOnError</td>
  346. <td valign="top">Should a failed compile halt the build?</td>
  347. <td valign="top">&quot;true&quot;(default)</td>
  348. </tr>
  349. <tr>
  350. <td valign="top">includes</td>
  351. <td valign="top">comma separated list of patterns of files that must be
  352. included. All files are included when omitted.</td>
  353. </tr>
  354. <tr>
  355. <td valign="top">includesfile</td>
  356. <td valign="top">the name of a file. Each line of this file is
  357. taken to be an include pattern</td>
  358. </tr>
  359. <tr>
  360. <td valign="top">listing</td>
  361. <td valign="top">Produce a listing (off by default). Listings go to the
  362. current output stream</td>
  363. <td valign="top">&quot;on&quot;, &quot;off&quot; (default)</td>
  364. </tr>
  365. <tr>
  366. <td valign="top">outputFile</td>
  367. <td valign="top">filename of output</td>
  368. <td valign="top">&quot;example.exe&quot;</td>
  369. </tr>
  370. <tr>
  371. <td valign="top">owner</td>
  372. <td valign="top">restrict disassembly by setting the 'owner' string</td>
  373. <td valign="top">&quot;secret&quot;</td>
  374. </tr>
  375. <tr>
  376. <td valign="top">resourceFile</td>
  377. <td valign="top">name of resource file to include</td>
  378. <td valign="top">&quot;resources.res&quot;</td>
  379. </tr>
  380. <tr>
  381. <td valign="top">srcDir</td>
  382. <td valign="top">source directory (default = project directory)</td>
  383. <td valign="top"></td>
  384. </tr>
  385. <tr>
  386. <td valign="top">targetType</td>
  387. <td valign="top">Type of target. library means DLL is output. </td>
  388. <td valign="top">&quot;exe&quot;(default), &quot;library&quot;</td>
  389. </tr>
  390. <tr>
  391. <td valign="top">verbose</td>
  392. <td valign="top">output progress messages</td>
  393. <td valign="top">&quot;on&quot;, &quot;off&quot; (default)</td>
  394. </tr>
  395. </table>
  396. <p>
  397. Example</p>
  398. <pre>&lt;ilasm
  399. outputFile=&quot;app.exe&quot;
  400. verbose=&quot;on&quot;
  401. listing=&quot;on&quot;
  402. owner=&quot;secret&quot;
  403. /&gt;
  404. </pre>
  405. <hr>
  406. <p align="center">Copyright &copy; 2000 Apache Software Foundation. All rights
  407. Reserved.</p>
  408. </body>
  409. </html>