Tooling that allows compilation of MVC Razor views as part of build and publish. NOTE: future work on Razor compilation is now being handled in the Razor repo. See the README for more details.
Permalink
Failed to load latest commit information.
.github Updated the file content Dec 13, 2017
.vsts-pipelines/builds [automated] Change default branch to master Jul 2, 2018
build Update dependencies.props Aug 26, 2018
src Fix microbuild signing configuration Sep 28, 2018
test automated: bulk infrastructure updates. Update bootstrapper scripts a… Sep 29, 2018
testapps automated: bulk infrastructure updates. Update bootstrapper scripts a… Sep 29, 2018
.appveyor.yml [automated] Change default branch to master Jul 2, 2018
.gitattributes Initial commit Aug 16, 2016
.gitignore Undo compatibility error messages Jan 22, 2018
.travis.yml [automated] Change default branch to master Jul 2, 2018
CONTRIBUTING.md Update CONTRIBUTING.md Jul 24, 2018
Directory.Build.props Fix microbuild signing configuration Sep 28, 2018
Directory.Build.targets Upgrade to netcoreapp22 May 8, 2018
LICENSE.txt Update LICENSE.txt text Jul 3, 2017
NuGet.config Use MSBuild to set NuGet feeds instead of NuGet.config Oct 2, 2017
NuGetPackageVerifier.json Remove docs exclusion from NuGetPackageVerifier.json. Jun 20, 2017
README.md Updated the readme file to reflect the PR feedback Dec 13, 2017
RazorViewCompilation.sln Remove Precompilation_WorksForViewsUsingDirectoryTraversal Aug 7, 2018
build.cmd Update bootstrappers Oct 9, 2017
build.sh Update bootstrappers Oct 9, 2017
korebuild-lock.txt Update dependencies.props Aug 26, 2018
korebuild.json [automated] Change default branch to master Jul 2, 2018
run.cmd Update bootstrappers Oct 9, 2017
run.ps1 automated: bulk infrastructure updates. Update bootstrapper scripts a… Sep 29, 2018
run.sh automated: bulk infrastructure updates. Update bootstrapper scripts a… Sep 29, 2018
version.props Bumping version from 2.2.0 to 3.0.0 Jun 28, 2018

README.md

ASP.NET Core MVC Precompilation

NOTE: This repo is solely for maintenance of the existing MVC precompilation feature. Future work on Razor compilation is now being handled in the Razor repo. See aspnet/Razor#1740 for additional details.

AppVeyor: AppVeyor Travis: Travis

The Razor syntax provides a fast, terse, clean, and lightweight way to combine server code with HTML to create dynamic web content. This repo contains tooling that allows compilation of MVC Razor views as part of build and publish.

Installation and usage

Referencing the Microsoft.AspNetCore.Mvc.Razor.ViewCompilation package

  • If you're targeting ASP.NET Core 2.0 or higher on netcoreapp2.0, a reference to the Microsoft.AspNetCore.Mvc.Razor.ViewCompilation package is added by Microsoft.AspNetCore.All and you do not need to explicitly reference it.
  • For desktop targeting projects or projects targeting ASP.NET Core 1.x, add a package reference to the appropriate version of Microsoft.AspNetCore.Mvc.Razor.ViewCompilation in your project:
<ItemGroup>
  <PackageReference Include="Microsoft.AspNetCore.Mvc.Razor.ViewCompilation" Version="1.1.1" />
</ItemGroup>

Enabling view compilation

View compilation as part of publishing is enabled by default if you're referencing the Web SDK (Microsoft.NET.Sdk.Web) that ships with .NET Core 2.0 or later versions. For older versions, add the MvcRazorCompileOnPublish property to your project:

<PropertyGroup>
  <MvcRazorCompileOnPublish>true</MvcRazorCompileOnPublish>
</PropertyGroup>

Alternatively, you may wire up the MvcRazorPrecompile target to a build event:

 <Target 
    Name="PrecompileRazorViews" 
    AfterTargets="Build"
    DependsOnTargets="MvcRazorPrecompile" />

Options

Some aspects of view compilation can be configured by editing the project:

  • MvcRazorCompileOnPublish: Setting this to false turns off all functions of view compilation that are enabled as part of publishing.

  • MvcRazorExcludeViewFilesFromPublish: Enabling MvcRazorCompileOnPublish prevents .cshtml files from being published. This option disables this behavior. Note: ASP.NET Core Mvc does not support updateable precompiled views. Any modifications to published cshtml files will be ignored if a precompiled view is discovered for that path.

  • MvcRazorExcludeRefAssembliesFromPublish: Enabling MvcRazorCompileOnPublish causes the target to prevent the refs directory from being published. This option disables this behavior. Note: Setting this option is useful if your application is using a mix of precompiled and runtime compiled views.

  • MvcRazorFilesToCompile: An item group that specifies view files to compile. By default this includes all .cshtml files marked as content.

This project is part of ASP.NET Core. You can find samples, documentation and getting started instructions for ASP.NET Core at the Home repo.