Unlike the Vsix which depends on Visual Studio's single file generator tooling, RazorGenerator.MsBuild allows precompiling views independent of Visual Studio. It works by dynamically generating C# files for Views during build which
are then compiled like ordinary files in the project.
Installing the package
The package depends on NuGet's target import feature that was introduced in NuGet 2.5. Additionally, having auto package restore greatly simplifies dealing with not-checking in packages. It is highly recommended upgrading to NuGet v.2.7 or higher when using
To use the package, install the package using NuGet.
Verifying if it works
To verify that the Msbuild target has been set up correctly, check if files are being generated under the obj\CodeGen directory of your application.
Customizing the target
The target file assumes some default values for properties and itemgroups. These values can be overridden from your csproj
- RazorSrcFiles - ItemGroup - the files that the generator precompiles. Defaults to any cshtml file under the project's directory. For instance, to customize it to only include files under the Views directory, add this
ItemGroup(http://msdn.microsoft.com/en-us/library/646dk05y%28v=VS.80%29.aspx) to your csproj.
<RazorSrcFiles Include="Views\**\*.cshtml" />
- RazorViewsCodeGenDirectory- the directory at which files are precompiled to. Defalts to obj/CodeGen directory. You can change this by specifying a value for this property from your csproj
: Property and Item group declarations must occur before the msbuild target Import