Thursday, October 02, 2008

ASP.NET MVC Web Site Templates (Preview 5)

The default model for ASP.NET MVC is the 'Web Application Project'. This makes sense especially when you consider the amount of emphasis the ASP.NET MVC team is putting on TDD.

At the same time I really like the ASP.NET 'Web Site' model. I just find that I'm more productive with it. I decided to hack together some templates for making ASP.NET MVC development possible using the 'Web Site' model.

A few caveats. I couldn't figure out how to get template filtering to work in Visual Studio so I pulled it out. This means that the item templates will probably show up in the IDE more often than they should. If you have any tips on getting template filtering to work properly please let me know.

The templates are for ASP.NET MVC Codeplex Preview 5. The templates only support C#. TDD is not supported.

The project template is contained in this zip file:

MvcWebSite.cs.zip (157 KB)

The item templates are contained in these zip files:

ControllerItemTemplate.cs.zip (.97 KB)
MvcViewPageItemTemplate.cs.zip (2.15 KB)
MvcViewUserControlItemTemplate.cs.zip (1.4 KB)
MvcViewMasterPageItemTemplate.cs.zip (2.35 KB)

I find the 'My Templates' feature in VS to be kind of hokey so I installed these templates directly into the Visual Studio 2008 directory.

Here are the steps to get the templates to show up in Visual Studio:

  1. Copy 'MvcWebSite.cs.zip' directly (don't unzip it) into 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\Web\CSharp\1033'
  2. Copy the remaining item templates into 'C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\ItemTemplates\Web\CSharp\1033'
  3. run the following from the command line: 'devenv.exe /installvstemplates'
The 'File -> New Web Site' dialog should now display a project item called 'ASP.NET MVC Web Site'.

In order for CSS styles to be applied correctly you will need to change the 'Virtual path' property of the web site to '/' (root). Scott Guthrie outlines this process below.

http://weblogs.asp.net/scottgu/archive/2006/12/19/tip-trick-how-to-run-a-root-site-with-the-local-web-server-using-vs-2005-sp1.aspx

NOTE TO MICROSOFT: I would be nice if '/' was the default when creating a new web site.
#    Comments [0] |