Web Application Project Compilation And NAnt

I am working on automated builds for our projects. I am quite excited about it, since it feels like taking back the power over the creation of the code. Not only that, the 'auto-magic' dissolves ones you do it manually and things become simple. You run the script, the script is failing, you need to fix the issue and you want the issue to be simple in order to A) locate it quickly B) fix in the least effort applied.

Saying that, I have to admit that having a strong build scripts takes time to develop as well. Thanks to the (NAnt/NAntContrib) community this is not a difficult task even for a novice like myself. And lets get back to the concept - simplicity.

If you look around, lots of build scripts are a single file that is doing it. But isn't this a sort of violation of SRP? One of the projects' build file in the entire solution should not be too overwhelming to read just because there's a bunch of projects and global properties. So I decided to partition.

In my case the partitioning is working great (master build file and child build files). Parent build file acts as a trigger for each individual project, invoking the right target.

This is great even with the projects that have dependencies on other projects in solution. The old plain CSC is doing it all.

Web Application Project (WAP) - an absolutely different creature. I failed to launch WAP compilation with aspnet_compiler. So I used msbuild to compile the web application project and trace what it was doing. To my surprise it leveraged csc.exe compiler to do the job. When the web application was requested in browse, the aspnet_compiler kicked in. So does that mean there is no need in aspnet_compiler to compile a web site?

PS: I will make a separate entry on Partitioned build files.

Update: please read my comment below. I have found a temporary (and maybe a permanent) way to achieve the goal with WAP compilation.

6 Comments

  • Hi Sean,

    I am working on the exact process myself. Can you share your master and child build files? I will submit mine here as well.

  • @Al
    I am still in the process of figuring out what to do, but generally I got the sense of what is happening with Web Application Project (WAP) time at compilation time. Again, this is my current understanding and I am not sure it's absolutely correct. The story goes like this:

    you can't use aspnet_compiler.exe on the WAP. You should use csc.exe instead to compile all the code beside (.cs and .designer.cs) into the assembly that should reside under Bin folder in web application. Have your web server (IIS) to point to the web application folder. Hit the web app in browser and then, ASP.NET will invoke aspnet_compiler to compile the page and populate it's cache if it's a first hit or the .aspx / .ascx has been modified.

    This is working great for our scenario, but if you want to have everything compiled into a single assembly to have .aspx / .ascx compiled into code, I presume you have to run a second pass compilation using aspnet_compiler.exe, but this time around it will not complain as you have the code beside compiled already.

    If you want the build files, send me an e-mail at feldman {dot} sean {dot} {at} gmail {dot} com. I will be posting a normalized version later this month, also to have deployment options. Would love to learn how to optimize the whole thing and get partitioned build style even more automated and easy.

    Sean

  • Compiling an web application into a single file is possible from Visual Studio 2005 SP1 onward. In the original VS.2005 (or if you make a web site rather than a web application), the aspnet_compiler.exe was always needed and would produce multiple output assembles.

    I got it to work as follows for a Visual Studio 2005 web application project, on a build machine with NaNT but without the IDE.
    - Uninstall the .Net framework 2.0 SDK if it was installed before 11/29/2006
    - Install the current version of the .Net framework 2.0 SDK, dated 11/29/2006
    - Build your web application into a single assembly using
    sources: all .cs files as specified in the csc command line by the IDE
    references: all referenced assemblies as specified by the IDE. We use local copies of assemblies like System.Web.Extensions.dll in our build script, so that we can better version control them
    - Publish as follows:
    copy the output dll of csc and all referenced dll's to yoursite\bin
    copy all aspx, ascx and resx from the project directory tree to yoursite. We do it like this:








    copy images, etc. to the proper directories

    After this procedure I ended up with a working web application produced by my NaNT build script.

  • @Berend,
    you are absolutely right, with WAP projects type it is simply compiling the code behind with CSC task into a library and throwing that one into the BIN folder. At runtime, aspnet_compile will pick up the requested page and use it with the compiled previously dll and populate the cache. You made the right comment on having SP1 for VS.NET 2005. Alternatively, you can use vs.net 2005 without sp1, but then you have to have WAP installed.

  • i need help form ur side...

    am new in web application, so how to build the web application without using vs IDE.


    advance thanks.

  • @Sathishkumar,
    I am not entirely sure what you mean by that, but building I would do in VS (after all it's a great editor). Compilation, packaging and deployment I would do with another tool (script). Can recommend to look into NAnt or MSBuild or combination of both of them. If you investigate the project file, you will see that it's actually a very simple MSBuild script. Hope this helps.

Comments have been disabled for this content.