January 2005 - Posts

Automatic code file compilation in ASP.NET 1.x

Earlier this week I held a three day ASP.NET 2.0 training session for one of our clients who are early adopters of the technology. Two of the topics we discussed were build providers and the code separation models. Build providers in ASP.NET 2.0 is a brilliant solution for the ever returning question of “what is the easiest way to deploy my code?” Having a code folder where you can drop off your C# or Visual Basic.NET source files and have them built automatically is a great feature. Few people are aware that you can exploit the compilation model in ASP.NET 1.x to achieve something similar. If you add an ASPX page the virtual folder and make its src attribute point to a source file, this file will be compiled when ASP.NET detects that it has changed. This isn’t as elegant as the ASP.NET 2.0 code folder, but it is a solution if you need automatic, server side compilation of classes.

How to use reserved words as identifiers

A little known feature in C# is that you can place an @ in front of an identifier. This is useful when you want to use a reserved word such as class as an identifier. Dynamic code generation has inherited the identifier “clazz” from the Jakarta Commons project. However in C# you can give you ModuleBuilder a correctly spelled identifier.

TypeBuilder @class=module.DefineType ("TempClass",TypeAttributes.Public);

Developing ASP.NET applications in VS2003 without IIS

April 25 thru April 26, 1998 the Cassini spacecraft flew by Venus. This is still one of the highlights from its journey through space. Venus is also the codename of Microsoft’s ASP.NET 2.0 project. Visual Studio.NET 2005 uses an embedded web server based on the Cassini light-weight web server to run “Venus” applications. The embedded web server is a great feature for a number of reasons. You can develop ASP.NET application with a restricted account without spending hours configuring Internet Information Server, group memberships, DACLs and other things. Further you don’t have to have your application setup as a virtual directory in IIS. In fact, you don’t have to have IIS installed at all!

Visual Studio .NET 2005 hasn’t got an official release date yet, but sometime around July is a qualified guess. However, you can ditch Internet Information Server today and run and debug your ASP.NET applications with Cassini from Visual Studio .NET 2003. All you have to do is some additional project configuration:

  1. Download and install Cassini. Cassini can be downloaded from http://www.asp.net/Projects/Cassini/Download/Default.aspx?tabindex=0&tabid=1
  2. Register the cassini.dll in the Global Assembly Cache (GAC). You can use the Microsoft .NET Framework 1.1 Configuration tool located in the Administrative Tools directory or the gacutil command to do this. The Cassini assembly has a strong name, so there is no need to sign it unless you’ve built your own customized version.
  3. Create a new Class Library project.
  4. Add a reference to the System.Web.dll assembly.
  5. Add a web form to the project. Class library projects haven’t got the same wizards as web projects, so you’ll have to improvise. I suggest you add a new HTML page, and rename this to Default.aspx.
  6. Right click the project and choose “Properties”.
  7. On the Configuration Properties > Build page, change the Output Path setting to “bin\”.
  8. On the Configuration Properties > Debugging page, change the Debug Mode setting to “Program”.
  9. Click the Apply button.
  10. On the Configuration Properties > Debugging page, enter the path to the CassiniWebServer.exe file in the Start Application setting.
  11. On the Configuration Properties > Debugging page, enter the path for the project and the port number you want Cassini to use in the Command Line Arguments field. For example: "C:\Documents and Settings\anders.noras\My Documents\My Projects\Examples\CassiniInVs2003"  8080
  12. Close the properties dialog and press the play button.
  13. When the Cassini Personal Web Server dialog appears, click the link and your ASP.NET application should start.

If your user account doesn’t have administrative privileges, an administrator must grant your account modify and write access to the Temporary ASP.NET Files folder. You’ll also need administrative privileges to register the cassini.dll in the GAC.

You’ll have to navigate through some asteroid fields when using Cassini instead of IIS, the most apparent are the missing ASP.NET wizards and not being able to drag user controls onto a web form. However, for an experienced developer, these obstacles are minor and I believe that the trade-off is justified by the comfort of being IIS idependant.

New Year's "Cruft"! Everything must go!

Back in 2002, Doctor Dobb’s Journal columnist Verity Stob wrote an excellent piece about “cruft”, which is the inevitable state of decay that ensues as soon as you start using any operating system. My laptop has become decrepit - cruft force 8. At force 8, the entropy has reached the point where your computer defies Newton’s first law of motion and installing additional software actually improves performance. Therefore; this is the last post I will be writing on my current Windows installation. I’ve been defeated by “cruft” – everything must go! When I get back to my office tomorrow, my trusty Dell Latitude D800 is having a well deserved hard disk reformat, and I’m going to reinstall all my software.

I’ve compiled a list of the tools that will have the honor of being installed on my virgin Windows XP installation. If there are other tools you think I should install, speak now or forever hold your peace. In addition to all the baseline applications such as Microsoft Office 2003 Professional, Microsoft Visual Studio .NET 2003 and similar, I will be installing:

I’ll also be installing lots of frameworks such as Spring.NET, NUnitASP and many more, but first and foremost I’m after feedback on must-have tools I’ve missed out on. A change from previous setups is that I’m not going to install any Microsoft SQL Servers or BizTalk Servers directly under my desktop OS, these will all be Microsoft Virtual Server 2005 instances that I can start on demand. I’ll also investigate the possibilities of using Microsoft Cassini instead of Microsoft Internet Information Server to host ASP.NET applications that are under development, to mimic Microsoft Visual Studio .NET 2005’s ASP.NET debug environment with Microsoft Visual Studio .NET 2003. If I succeed, rest assured I will brag about it here.

When reinstalling I’m also going to ask our network admin to demote my domain account from local administrator to a normal user, and I’ll start practicing “development with least privilege” once and for all.

I’ve got my fingers crossed and I believe that my new year’s restoration will go as planned. The next time you’ll hear from me I’ll be back at cruft force 0 with the SysInternals “Blue Screen of Death” screensaver installed, no more than nine directories under my root and every thing running crisply. Wish me luck!

Happy New Year!

Last year I got back into the blogging game to be sure that I still was hip. After all, ABC declared bloggers people of the year 2004. My most read post in December was the off topic “Best Albums of 2004” list. This warms my heart, because I’m such a list geek.* So when I saw this Playlist Meme in Wikes Joiners blog, I knew I had to have one in my blog as well.
Before I reveal the 10 most recent songs on my iTunes playlist, you must read the “Playlist Meme rules”:

  1. Open up the music player on your computer.
  2. Set it to play your entire music collection.
  3. Hit the "shuffle" command.
  4. Tell us the title of the next ten songs that show up (with their musicians), no matter how embarrassing. That's right, no skipping that Carpenters tune that will totally destroy your hip credibility. It's time for total musical honesty. Write it up in your blog or journal and link back to at least a couple of the other sites where you saw this.
  5. If you get the same artist twice, you may skip the second (or third, or etc.) occurrences. You don't have to, but since randomness could mean you end up with a list of ten songs with five artists, you can if you'd like.

My ten most recently played choons are:

  1. Us 69 – Yesterday’s Folks
  2. Seu Jorge – Mangueira
  3. De La Soul ft. MF Doom – Rock Co.Kane Flow

  4. Mylo – Drop the Pressure (Erol Alkan remix)
  5. Fat Freddy’s Drop – Hope
  6. Beans – Death by Sophistication
  7. A Girl Called Eddy - People Used to Dream
  8. Roland Brival – Tunji
  9. Javi P3Z Orquesta – El Pinball
  10. Bahamadia and The Roots – Wordplay

This is probably the last off topic post for a while. As soon as the regular workdays start on Monday, I’ll return with some more interesting programming related posts. Until then, enjoy the rest of the new year’s weekend. Relive some of the tsunami victims by donating to the Red Cross or another organization. A happy new year to all my readers!

* Yes, High Fidelity is one of my favorite books.