RazorGenerator
Generator Types
MvcHelper
: Creates a static type that is best suited for writing Mvc specific helper methods.MvcView
: Create a WebViewPage which allows the use of precompiled MVC views.WebPage
: Creates a WebPage type that can be used as WebPages Application Part (such as _Admin and RazorDebugger).WebPagesHelper
: Creates a HelperPage type that is suited for precompiling and distributing WebPages helper.Template
: Generator based on T4 preprocessed template.
Usage in an MVC app
- Install the 'RazorGenerator.Mvc' package, which registers a special view engine
- Go to an MVC Razor view's property and set the
Custom Tool
toRazorGenerator
- Optionally specify a value for
Custom Tool Namespace
to specify a namespace for the generated file. The project namespace is used by default. - Optionally specify one of the generators in the first line of your Razor file. A generator declaration line looks like this:
@* Generator: MvcHelper *@
. If you don't specify this, a generator is picked based on convention (e.g. files under Views are treated asMvcViews
) NOTE: The selection has other criteria such as detecting "Helper" in the filename and choosingWebPagesHelper
for those. - You'll see a generated .cs file under the .cshtml file, which will be used at runtime instead of the .cshtml file
- You can also go to the nuget Package Manager Console and run
Enable-RazorGenerator
to enable the Custom Tool on all the views. - And to cause all the views to be regenerated, go to the nuget Package Manager Console and run
Redo-RazorGenerator
. This is useful when you update the generator package and it needs to generate different code. - ----------------------------------------------------------------
download RazorGenerator extension
in cshtml under app_code
@* Generator: MvcHelper DisableLinePragmas: true Namespace: BSS.SubProj.Web GeneratePrettyNames : true ExcludeForCodeCoverage : true*@
--helper build action none and custom tool:RazorGenerator
--generated cs- build action compile