How to speed up ASP.NET web development?
Almost every ASP.NET developer heard of or used ReSharper Visual Studio Addon or CodeRush from DevExpress. Those tools claim to speed up a coding process up to 25%. However, almost nobody realizes that most of the time an asp.net web developer just waiting for a project to compile. About a year ago I had to work on a big product. Compilation of the whole solution usually took about 2-3 minutes. I felt like most of my work day I was just waiting for a project to compile. So, I came up with the following techniques.
1. “F5 Start Debugging” evil.
Never, never hit F5. This slowest thing that you can do. First of all, if it is possible use localhost IIS instead of Visual Studio built-in HTTP server (aka Cassini). Better to test your project in a real environment. During my carrier, I had a lot of situations when a project worked in Cassini but didn’t work in IIS and vice versa.
Compile your solution and open it in a browser. You don’t need to hit F5. Just type http://localhost/YourApplication/Default.aspx and your test environment should be ready. You can make changes to your project. For the code behind changes, you need to recompile the project and then hit refresh in the browser. For ASPX changes, just save the file and then hit refresh in the browser.
For a built-in web server, you need to hit F5. It is a necessary step that can’t be avoided, but do it just one time. Again another point for localhost IIS. Copy an URL something like http://localhost:1234/YourApplication/Default.aspx and paste it into a new browser window. You can stop debugging now. You should still have one browser window open with your project in it. Cassini is still running, so you can do the same update process for IIS. Below is a little screencast video of what I mentioned above. As an example, I took my ColorPicker Control project.
Use the following shortcuts: Ctrl-S (Save), Shift-F6 (Build Current Project), F6 (Build Solution). Very rarely build a whole solution. Usually, it is enough to build a current project that you changed. If you need to debug an application, use attach to process command. You can use the following macros to automate this process:
Cassini:
Public Sub AttachToFirstDevWebServer()
Dim process As EnvDTE.Process
For Each process In DTE.Debugger.LocalProcesses
If (Path.GetFileName(process.Name).ToLower() = "webdev.webserver.exe") Then
process.Attach()
Exit Sub
End If
Next
MsgBox("No ASP.NET Development Server found")
End Sub
IIS:
Sub AttachDebugger()
Try
Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
Dim dbgeng(1) As EnvDTE80.Engine
dbgeng(0) = trans.Engines.Item("Managed")
Dim proc2 As EnvDTE80.Process2
proc2 = dbg2.GetProcesses(trans, "").Item("w3wp.exe")
proc2.Attach2(dbgeng)
Catch ex As System.Exception
MsgBox(ex.Message)
End Try
End Sub
2. Multiple projects application structure.
Everybody heard about DAL and multiple tiers of an application. However, usually, developers do not break application tiers into different projects. This is a really useful technique. Why do you need to recompile a business logic layer for a small UI change? UI tier should be in its own project, so you can recompile only UI level and nothing else. Again just press Shift-F6.
4. Virtual hard drive.
Visual Studio is very chatty with a hard drive, especially during compilation. If you are using a laptop as your primary development machine then it probably has 5400 rpm hard drive. Microsoft suggests using with Visual Studio 7200 rpm hard drives or even 10000 rpm hard drives. So, you might experience slowness. Virtual hard drive might help you. Copy your project to Virtual Hard Drive. Modify environment variables Temp and Tmp, so they point to Virtual Hard Drive as well. By using this technique I reduced my compilation time from 3 minutes to 45 seconds.
3. Firefox addons.
Use Firefox as your primary test browser. It has a lot of useful addons, which might help you with web development. Lately, IE8 is catching up with Firefox, but it is still far behind.
- Firebug
I can’t imagine my life without firebug. You can do a lot of editing straight in firebug with a live preview. Just copy and paste a CSS code when you are done tweaking it.
Take a look:
-
Web Developer addon
Has a lot of features, but I meanly use: clear cache, find broken images, resize a window, view generated code, show passwords, display ruler, display guides. -
ColorZilla Need quickly grab a color from a website? Want to rip off a gradient? ColorZilla is your tool.
-
PixelPerfect If you are working closely with designers then you need this tool to make a perfect match of design and HTML.
-
XRefresh If you have two monitors, then you absolutely need to have this tool. It automatically refreshes a browser when you do change to a source code. It also has IE support.
-
IE Tab You need this addon if you need to test your website in IE. A single click is going to switch rendering engines. You can set certain sites always use IE rendering engine, for example, MOSS intranet sites.
-
YSlow You need this addon to optimize the client side performance of your website.
-
FireShot Screenshot tool with anotations.