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 this package.

To use the package, install the package using NuGet.

Install-Package RazorGenerator.MsBuild

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
<ItemGroup>
    <RazorSrcFiles Include="Views\**\*.cshtml" />
</ItemGroup>
<RazorViewsCodeGenDirectory>$(Temp)\Myproject\RazorTempFiles\/<RazorViewsCodeGenDirectory>

Note: Property and Item group declarations must occur before the msbuild target Import