Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MVC Views in NuGet Modules

In making NuGet modules for my company's internal re-use library I finally embarked on making a module with a visual component. The .cshtml file for this module will reside in a location specific to modules (not the standard "Views" folder) so I have been putting a secondary web.config in the same folder with the view to allow for MVC and Razor.

The problem becomes, although I can specify a version of MVC as a dependency in my .nuspec file, I don't want to have to be version specific being that all the functionality I am using in my views exists in all versions of MVC.

Is there a way I can get a view into a specific (and non-traditional) folder and have it operate using shared MVC binaries and configuration? Is it possible to do this in all types of projects without requiring any extra steps for a person to take after installing the NuGet package?

like image 535
Paul Caponetti Avatar asked Mar 30 '15 20:03

Paul Caponetti


1 Answers

You have few options:

  1. Use razor generator to compile views into classes - https://razorgenerator.codeplex.com
  2. Include views as embedded resources and write VirtualPathProvider to get them ( example at http://www.ianmariano.com/2013/06/11/embedded-razor-views-in-mvc-4/)
  3. Inside nuget package create PowerShell script with additional steps

The problem with dependency into Asp.Net MVC is that it wasn't always backwards compatible, but this you will have to check yourself

like image 125
Piotr Stapp Avatar answered Nov 09 '22 09:11

Piotr Stapp