Posts
208
Comments
1144
Trackbacks
51
MVC Portable Areas – Web Application Projects

This is the first post in a series related to build and deployment considerations as I’ve been exploring MVC Portable Areas:

Portable Areas is a relatively new feature available in MvcContrib that builds upon the new feature called Areas that was introduced in MVC 2. In short, portable areas provide a way to distribute MVC binary components as simple .NET assemblies rather than an assembly along with all the physical files for the views. At the heart of portable areas is a custom view engine that delivers the *.aspx pages by pulling them from embedded resources rather than from the physical file system. A portable area can be something as small as a tiny snippet of html that eventually gets rendered on a page, to something as large as an entire MVC web application. You should read this 4-part series to get up to speed on what portable areas are.

Web Application Project

In most of the posts to date, portable areas are shown being created with a simple C# class library. This is cool and it serves as an effective way to illustrate the simplicity of portable areas. However, the problem with that is that the developer loses out on the normal developer experience with the various tooling/scaffolding options that we’ve come to expect in visual studio like the ability to add controllers, views, etc. easily:

I’ve had good results just using a normal web application project (rather than a class library) to develop portable areas and get the normal vs.net benefits. However, one gotcha that comes as a result is that it’s easy to forget to set the file to “Embedded Resource” every time you add a new aspx page. To mitigate this, simply add this MSBuild snippet shown below to your *.csproj file and all *.aspx, *ascx will automatically be set as embedded resources when your project compiles:

   1:  <Target Name="BeforeBuild">
   2:    <ItemGroup>
   3:      <EmbeddedResource Include="**\*.aspx;**\*.ascx" />
   4:    </ItemGroup>
   5:  </Target>

Also, you should remove the Global.asax from this web application as it is not the host.

Being able to have the normal tooling experience we’ve come to expect from Visual Studio makes creating portable areas quite simple. This even allows us to do things like creating a project template such as “MVC Portable Area Web Application” that would come pre-configured with routes set up in the PortableAreaRegistration and no Global.asax file.

posted on Monday, April 5, 2010 4:49 PM Print
Comments
Gravatar
# Off topic - page life cycle in MVC
Lei
4/28/2010 12:35 AM
Scott Allen states @ http://msdn.microsoft.com/en-us/magazine/dd942822.aspx:
"Code-behind can only encourage the practice of putting more logic into a view and, even worse, can introduce the traditional ASP.NET page life-cycle events to a view. Page life-cycle events are one feature of ASP.NET that the MVC framework tries very hard to hide."
Does that mean the Init, Load, Render etc events still exist for web pages in MVC, as it is still asp.net page?


Gravatar
# re: MVC Portable Areas – Web Application Projects
Steve
5/2/2010 8:29 AM
@Lei - Yes, they still exist. System.Web.Mvc.ViewPage actually inherits from System.Web.UI.Page. But to reiterate - their use is heavily discouraged in MVC.

Post Comment

Title *
Name *
Email
Comment *  
Verification

View Steve Michelotti's profile on LinkedIn

profile for Steve Michelotti at Stack Overflow, Q&A for professional and enthusiast programmers




Google My Blog

Tag Cloud