Hello, I have been doing a lot of "end of the year cleanup" type stuff this week in between Christmas and New Years, and two of those items have been to (a) upgrade all my projects from VS.2003 to VS.2005, and (b) setup automated builds using NAnt (I am new to NAnt, but have been a long time user of Ant on the Java platform, and I will say NAnt is great!).
Since I am working with VS.2005, I am running the latest build, which is nant-0.85-nightly-2005-12-13. I had no problem getting my class library (i.e. dll) and windows forms (i.e. exe) projects built using NAnt, but when I got to a ASP.Net web application project and also to a ASP.Net web service project, I ran into a few snags that I think I have now overcome. So I am writing this post to the users list to help others save the time I just spent figuring this out. I will also ask any of you NAnt committers or gurus to please jump in and reply to this thread if you see anything I have done that is either incorrect or redundant or inefficient (i.e. there is a better way to do things). All such dialog is much appreciated! OK, here we go. A web application and a web service are both forms of ASP.Net projects, so just about all of what I have to say applies to both types of NAnt builds. The big difference between ASP.Net.1.1 and ASP.Net.2.0 is that in ASP.Net.1.1 when you built your project in VS.2003, it created an output .dll file normally in your ./bin folder. The spooky thing about ASP.Net.2.0 is that it no longer creates such a file. In fact, when compiling inside of VS.2005 I am not sure what output it generates, but it must do something. At first I was really ticked at Microsoft, thinking something along the lines of "those idiots, don't they know that the value of doing nightly builds to flush out problems like your ASP.Net project no longer building because of some change in an underlying DLL the project references!". But then I did a little research and found that (a) in ASP.Net, you don't HAVE to compile things ahead of time because whenever you call up a page/service, the application server (IIS) will detect that the file is out of date and will do a compilation on the fly for you. But this causes a delay when a modified page is first hit because the compiler runs, so Microsoft provides a mechanism for precompiling the site ahead of time. You can Google for things about ASP.Net.2.0 precompiling, but in this email I'm going to stick to how to use the precompiler inside of a NAnt build so that we can catch compilation errors that could occur during continuous integration cycles. To build a NAnt build using this precompiler, we obviously have to know what the precompiler is called and where it resides. It resides in the .Net system folder itself, which for my version of .Net 2.0 is located at c:/windows/Microsoft.NET/Framework/v2.0.50727 (note this could be different after some future upgrade of .Net). The name of the precompiler program itself is aspnet_compiler.exe. Next, you need to know the command line options of aspnet_compiler.exe. For this I will refer you to MSDN - See http://msdn2.microsoft.com/en-us/library/ms229863.aspx. You can run the precompiler to compile "in place", but you can also give the precompiler an output folder name and it will compile everything you need, and move the compiled output as well as everything else it knows you need over to this new output folder. So when it comes time to deploy your ASP.Net application to a production server, you do not have to carefully copy certain files out of your development directory... you can simply copy this entirely new output folder created by the precompiler. That alone in my book makes it worth using the precompiler! So I setup my build file so that it generates this "ready to go" output folder. But there is one habit of the precompiler that I noticed. It is smart enough to only copy files it knows you need and leave files it knows you don't want to ship to the production server alone (i.e. and most importantly, your *.cs source files). But if it runs across files that it does not recognize the purpose of, it copies them also. Not good! So files like your *.build file used by Ant, files like the *.ssc files used by Visual Source Safe, your *.sln file, etc. get copied. So you have to do some post compiler cleanup before your output folder is ready to go. OK, so let's look at the actual build file. I have injected various comments into the file, all prefixed by COMMENT:. If you want to cut and paste this file as a start for your build file you can do so, but then go back and remove the COMMENT: statements as they are not valid XML and will break the file. I have also written a generous number of XML comments into the file that I have left in my permanent build file to explain what is going on to future maintainers of this build file. Oh yeah, this file is for a ASP.Net web application. <?xml version="1.0"?> <project name="MyWebApp" default="build" basedir="."> <description>Builds the MyWebApp project</description> <!-- - Property definitions --> <property name="debug" value="true" overwrite="false"/> <property name="dotnet" value="c:/windows/Microsoft.NET/Framework/v2.0.50727" overwrite="false" /> COMMENT: The above statement is where I tell this script where the aspnet_compiler.exe file resides... <property name="target" value="../MyWebApp.deploy" overwrite="false" /> COMMENT: The above statement defines the output (deployment) folder that the 'build' target will generate. I tried to make this a subdirectory of my actual project, but the precompiler would not allow that for some reason. Probably because it searches everything under the project folder to look for stuff to copy to the deployment folder, and would get confused in the recursion that would occur. <!-- - 'clean' Target --> <target name="clean" description="Remove all generated files"> <delete dir="${target}" /> </target> COMMENT: Note that to do a 'clean', all we had to do was to delete the entire output folder. <!-- - 'build' Target - - Precompiles this ASP.Net application - into the ../MyWebApp.deploy directory. --> <target name="build" description="compiles the source code"> <!-- - The precompiler will not compile the app if files - exist in the output directory, so we will delete - it before we run the precompiler. --> <delete dir="${target}" /> <!-- - Precompile the web site --> <exec basedir="." program="${dotnet}/aspnet_compiler.exe" commandline="-nologo -v MyWebApp ${target}" workingdir="." failonerror="true" /> <!-- - If the precompiler doesn't recognize the function of a file - it finds in the directory being precompiled, it copies that - file to the target folder. Therefore, it is necessary to do - a bit of cleanup after the precompiler to remove files we - do not want to deploy to the production server. --> <delete> <fileset> <include name="${target}/*.build" /> <include name="${target}/*.scc" /> <include name="${target}/*.sln" /> <include name="${target}/build.*" /> COMMENT: The above includes cover the files that I had in my project folder that I did not want to ship to the deployment folder, but you may have others that this set of includes do not catch. So I STRONGLY advise that when you run this build successfully for the first time, go look at the .deploy output folder and see if there are files in there that you do not want shipped to the production server. If you find them, then just come back here and add more <include> statements to this build file. </fileset> </delete> </target> </project> That does it, at least for my project. I also did exactly the same thing for a web service project I have. Since web service projects are just a variation on a web application project, it works exactly the same way. I hope this is helpful to somebody out in cyber space. Now, here is what I need if anyone can help me out: I have a plain vanilla class library (i.e. dll) project I need to build, but it has one web reference. In VS.2003, adding a web reference just caused VS.2003 to automagically generate the source code, which it put into a file named Reference.cs. But in VS.2005, Reference.cs is no longer generated, nor is any other source file I can find. So I have not yet figured out how to NAnt build this project because I get compiler errors due to the missing code (the stuff that used to be in Reference.cs). If you can tell me the incantations for this bit of black magic, please let me know. Thanks, Brad ------------------------------------------------------- This SF.net email is sponsored by: Splunk Inc. Do you grep through log files for problems? Stop! Download the new AJAX search engine that makes searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! http://ads.osdn.com/?ad_idv37&alloc_id865&op=click _______________________________________________ NAnt-users mailing list NAnt-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/nant-users