Skip to content
| Marketplace
Sign in
Visual Studio>Tools>Razor Single File Generator for MVC
Razor Single File Generator for MVC

Razor Single File Generator for MVC

Chris van de Steeg

|
16,501 installs
| (5) | Free
Single File Generator for Razor View files (.cshtml files) in an mvc project. Allows you to compile your razor views and thus distribute them without source code. Changelog: 1.0.5: Stopped using a custom buildprovider, using inheritance for code generation now. This should ...
Download

This tool allows you to compile your razor views and thus distribute them without source code.

Below is the how-to from the blogpost at: http://www.chrisvandesteeg.nl/2010/11/22/embedding-pre-compiled-razor-views-in-your-dll/

 

Step 1: Install the FileGenerator

(using this download)

Step 2: Create new mvc project

image

image

Step 3: Add a class library to hold the views

image

image

Step 4: Cut your Models & Views folders

image

Step 5: Paste them into the just created Class Library

image

Step 6: Copy the website’s web.config file

image

Step 7: Paste that web.config file into the class library

image

Step 8: Select all your .cshtml files in the class library and set the Custom Tool to ‘MvcRazorClassGenerator’

Does anyone have a suggestion on improving this step??

image

Step 9: Build your class library

Step 10: Add your class library to the references of the web application

image

image

Step 11: Add ‘Commons.web.mvc.precompiledviews.dll’ as a reference to your website

this dll is copied to the class library’s output folder (in this case ../EmbeddedViews/bin/debug’)

image

Step 12: Register your views by adding a line to the application_start in global.asax.cs

image

Step 13: Run your website!

Now, you will see the normal default website, even though there aren’t any views in your website path!

If you wish to override some views, just create the normal folders (eg /Views/Home) and add your views there, but don’t forget to copy back the deleted /Views/web.config back into your project then!

  • Contact us
  • Jobs
  • Privacy
  • Manage cookies
  • Terms of use
  • Trademarks
© 2025 Microsoft