Tuesday, November 22, 2011

ReSharper and external ASP.NET MVC views

The project I currently work in is based on ASP.NET MVC and, beside main Web project, it can be extended using additional plugin-style libraries, that we import from specified directories and register in main application. Those plugin libraries can contain additional view files (.aspx or .ascx) - to support that, we're storing it as embedded resources and we have custom VirtualPathProvider that resolves it in main Web application.

The problem we were struggling with for quite a long time was that ReSharper was unable to resolve those views correctly, getting lost on Control definition in the first line of view. This caused whole file to be not understood, a lot of errors and fix suggestions were showing up and with several views like this, the performance was dramatically low.

Recently I've spent some time to investigate it more carefully and it turned out that the reason is fairly simple. This has nothing to do with embedded resource setting or not standard file locations. The only thing to do was to place standard Web.config file for views in each external project that contains ASP.NET MVC views.

Here are the lines that ensures ReSharper knows what to do with .aspx/.ascx files (for ASP.NET MVC 2):

pageParserFilterType="System.Web.Mvc.ViewTypeParserFilter, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
pageBaseType="System.Web.Mvc.ViewPage, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
userControlBaseType="System.Web.Mvc.ViewUserControl, System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35">
<add assembly="System.Web.Mvc, Version=, Culture=neutral, PublicKeyToken=31BF3856AD364E35"
namespace="System.Web.Mvc" tagPrefix="mvc" />

No comments:

Post a Comment