[Archived] Tooling that allows compilation of MVC Razor views as part of build and publish. Project moved to https://github.com/aspnet/AspNetCore
Перейти к файлу
Nate McMaster 1f02768ddd Remove dependency on Microsoft.NETCore.App from the generated nuspec (#160) 2017-07-03 09:22:10 -07:00
build Use IsPackable instead of ExcludeFromPack 2017-06-20 13:47:40 -07:00
src Remove dependency on Microsoft.NETCore.App from the generated nuspec (#160) 2017-07-03 09:22:10 -07:00
test Add a test that always publishes in Debug 2017-06-27 15:37:19 -07:00
testapps Remove SimpleAppDesktopOnly 2017-06-30 15:14:26 -07:00
tools/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation-x86 Add support for pre-compiling desktop applications. 2017-05-30 22:41:06 -07:00
.gitattributes Initial commit 2016-08-16 15:04:46 -07:00
.gitignore Updated to use 0.4.0 version of IntegrationTesting package 2017-04-15 04:37:40 -07: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
LICENSE.txt Initial commit 2016-08-16 15:04:46 -07:00
NuGet.config Updating versions to preview3 2017-06-01 10:47:31 -07:00
NuGetPackageVerifier.json Remove docs exclusion from NuGetPackageVerifier.json. 2017-06-20 10:43:41 -07:00
README.md Add some details about view compilation options (#156) 2017-06-30 15:18:09 -07:00
RazorViewCompilation.sln Remove SimpleAppDesktopOnly 2017-06-30 15:14:26 -07:00
appveyor.yml travis + appveyor 2017-06-08 14:23:20 -07:00
build.cmd Adding Razor Precompilation 2016-08-19 10:35:45 -07:00
build.ps1 Change korebuild branch and fix argument forwarding in bootstrapper 2017-03-01 18:14:13 -08:00
build.sh Change korebuild branch and fix argument forwarding in bootstrapper 2017-03-01 18:14:13 -08:00
version.props Updating versions to preview3 2017-06-01 10:47:31 -07:00

README.md

ASP.NET Core MVC Precompilation

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.