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 14 KiB

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