[Archived] Tooling that allows compilation of MVC Razor views as part of build and publish. Project moved to https://github.com/aspnet/AspNetCore
Перейти к файлу
Ryan Nowak e64954c9c7 Undo compatibility error messages
We're going another way with Razor SDK interop. The Web SDK
will make a choice whether to enable MvcPrecompilation or RazorSDK, and
the Razor SDK will support all of the settings from MvcPrecompilation.
2018-01-22 15:50:31 -08:00
.github Updated the file content 2017-12-13 13:37:36 -08:00
build update deps 2018-01-20 19:09:57 -08:00
src Undo compatibility error messages 2018-01-22 15:50:31 -08:00
test Add support and tests for Razor SDK interop 2018-01-17 08:37:27 -08:00
testapps Undo compatibility error messages 2018-01-22 15:50:31 -08:00
.appveyor.yml Update bootstrappers 2017-10-09 12:45:37 -07:00
.gitattributes Initial commit 2016-08-16 15:04:46 -07:00
.gitignore Undo compatibility error messages 2018-01-22 15:50:31 -08:00
.travis.yml Adding libunwind8 to .travis.yml 2017-06-26 09:40:12 -07:00
CONTRIBUTING.md Initial commit 2016-08-16 15:04:46 -07:00
Directory.Build.props Use sources.props 2017-11-29 16:08:28 -08:00
Directory.Build.targets Use MicrosoftNETCoreApp21PackageVersion to determine the runtime framework in netcoreapp2.1 2017-11-17 13:00:26 -08:00
LICENSE.txt Update LICENSE.txt text 2017-07-03 14:07:18 -07:00
NuGet.config Use sources.props 2017-11-29 16:08:28 -08:00
NuGetPackageVerifier.json Remove docs exclusion from NuGetPackageVerifier.json. 2017-06-20 10:43:41 -07:00
README.md Updated the readme file to reflect the PR feedback 2017-12-13 13:34:04 -08:00
RazorViewCompilation.sln Add support and tests for Razor SDK interop 2018-01-17 08:37:27 -08:00
build.cmd Update bootstrappers 2017-10-09 12:45:37 -07:00
build.sh Update build tools to 2.0.2-rc1-15526 and dependencies to 2.0.1-rtm-105 2017-10-13 13:12:19 -07:00
korebuild-lock.txt update deps 2018-01-20 19:09:57 -08:00
korebuild.json Pin tool and package versions to make builds more repeatable 2017-11-01 18:05:30 -07:00
run.cmd Update bootstrappers 2017-10-09 12:45:37 -07:00
run.ps1 Update bootstrappers 2017-12-04 12:28:39 -08:00
run.sh Update bootstrappers 2017-12-04 12:28:39 -08:00
version.props Bump version to 2.0.2 2017-12-06 16:22:12 -08:00

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.