We have a heavily automated build system and a number of widely-used internal libraries. We use NuGet (and our own NuGet server) to pack up the libraries and make dependency tracking easy. Recently we started switching our MVC libraries to use RazorGenerator
and WebActivator to make project creation and management easy.
Here's our use case and our problem:
We have a package (MyPackage.MyArea) that has an MVC area in the root (Views/Home, Views/Other, etc). We install RazorGenerator.Mvc and RazorGenerator.Msbuild into the project. In the App_Start/RazorGeneratorMvcStart.cs the PrecompiledMvcEngine has the baseVirtualPath
set (Areas/MyArea). Then this project is packed up into a NuGet package.
And installed in MyFinalProject.
Because of NuGet package dependency, both RazorGenerator.Mvc and RazorGenerator.Msbuild are installed on MyFinalProject, which generates a new App_Start/RazorGeneratorMvcStart.cs file.
All seems well until I want to go to
http://localhost/MyArea/Home/Index I get served the final project ~/Views/Home/Index.cshtml
instead of the pre-compiled ~/Areas/MyArea/Home/Index.cshtml
This seems to be because the PrecompiledMvcEngine for MyFinalProject is added later than, and in front of, the engine from MyPackage.MyArea so when the MyArea HomeController Index action returns View(), the view engines list starts looking first through MyFinalProject,
finds a matching view in ~/Views/Home/Index.cshtml and quits looking, even though a more specific view is available in the next engine in the list.
There are (from what I can tell) 3 ways to work around this, each with issues:
1) Remove App_Start/RazorGeneratorMvcStart.cs from MyFinalProject, which is fine until the next time I update RazorGenerator.Mvc, at which point it gets re-added....
2) Alter the ViewEngines.Engines.Insert statement in MyFinalProject to insert AFTER the engine from MyPackage.MyArea, which is fine unitl I start dealing with multiple MVC view packages, which might each have this issue with each other...
3) Disable RazorGeneratorMvcStart from running in MyFinalProject by disabling the WebActivator line at the top of the file.
The problem is we don't want to do any of these, as they are all manual work-arounds and fixes. There are many developers working on many projects and we want to minimize the chance of encountering upkeep project creation issues by automating this as much as
possible, which is why we want to use pre-built and compiled areas and views for our common code, so we can centralize the look and feel of our code.
Does anyone have suggestions on how I can remove this conflict of areas, or perhaps remove RazorGenerator from MyFinalProject entirely?