You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The preceding code doesn't return any entity types, therefore no tracking is done. For more information about the EF tracking, see [Tracking vs. No-Tracking Queries](/ef/core/querying/tracking).
Copy file name to clipboardExpand all lines: aspnetcore/fundamentals/routing.md
+2Lines changed: 2 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -449,6 +449,8 @@ Using a template is generally the simplest approach to routing. Constraints and
449
449
Complex segments are processed by matching up literal delimiters from right to left in a [non-greedy](#greedy) way. For example, `[Route("/a{b}c{d}")]` is a complex segment.
450
450
Complex segments work in a particular way that must be understood to use them successfully. The example in this section demonstrates why complex segments only really work well when the delimiter text doesn't appear inside the parameter values. Using a [regex](/dotnet/standard/base-types/regular-expressions) and then manually extracting the values is needed for more complex cases.
451
451
452
+
[!INCLUDE[](~/includes/regex.md)]
453
+
452
454
This is a summary of the steps that routing performs with the template `/a{b}c{d}` and the URL path `/abcd`. The `|` is used to help visualize how the algorithm works:
453
455
454
456
* The first literal, right to left, is `c`. So `/abcd` is searched from right and finds `/ab|c|d`.
Copy file name to clipboardExpand all lines: aspnetcore/mvc/views/view-compilation.md
+81-5Lines changed: 81 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -4,20 +4,96 @@ author: rick-anderson
4
4
description: Learn how compilation of Razor files occurs in an ASP.NET Core app.
5
5
ms.author: riande
6
6
ms.custom: mvc
7
-
ms.date: 4/8/2020
7
+
ms.date: 04/13/2020
8
8
uid: mvc/views/view-compilation
9
9
---
10
10
# Razor file compilation in ASP.NET Core
11
11
12
12
By [Rick Anderson](https://twitter.com/RickAndMSFT)
13
13
14
-
::: moniker range=">= aspnetcore-3.0"
14
+
::: moniker range=">= aspnetcore-3.1"
15
+
16
+
Razor files with a *.cshtml* extension are compiled at both build and publish time using the [Razor SDK](xref:razor-pages/sdk). Runtime compilation may be optionally enabled by configuring your project.
17
+
18
+
## Razor compilation
19
+
20
+
Build-time and publish-time compilation of Razor files is enabled by default by the Razor SDK. When enabled, runtime compilation complements build-time compilation, allowing Razor files to be updated if they're edited.
21
+
22
+
## Enable runtime compilation at project creation
23
+
24
+
The Razor Pages and MVC project templates include an option to enable runtime compilation when the project is created. This option is supported in ASP.NET Core 3.1 and later.
25
+
26
+
# [Visual Studio](#tab/visual-studio)
27
+
28
+
In the **Create a new ASP.NET Core web application** dialog:
29
+
30
+
1. Select either the **Web Application** or the **Web Application (Model-View-Controller)** project template.
31
+
1. Select the **Enable Razor runtime compilation** check box.
32
+
33
+
# [.NET Core CLI](#tab/netcore-cli)
34
+
35
+
Use the `-rrc` or `--razor-runtime-compilation` template option. For example, the following command creates a new Razor Pages project with runtime compilation enabled:
36
+
37
+
```dotnetcli
38
+
dotnet new webapp --razor-runtime-compilation
39
+
```
40
+
41
+
---
42
+
43
+
## Enable runtime compilation in an existing project
44
+
45
+
To enable runtime compilation for all environments in an existing project:
46
+
47
+
1. Install the [Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation/) NuGet package.
48
+
1. Update the project's `Startup.ConfigureServices` method to include a call to <xref:Microsoft.Extensions.DependencyInjection.RazorRuntimeCompilationMvcBuilderExtensions.AddRazorRuntimeCompilation*>. For example:
## Conditionally enable runtime compilation in an existing project
61
+
62
+
Runtimecompilationcanbeenabledsuchthatit's only available for local development. Conditionally enabling in this manner ensures that the published output:
Nocodechangesareneededintheproject's `Startup` class. At runtime, ASP.NET Core searches for an [assembly-level HostingStartup attribute](xref:fundamentals/configuration/platform-specific-configuration#hostingstartup-attribute) in `Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation`. The `HostingStartup` attribute specifies the app startup code to execute. That startup code enables runtime compilation.
*Seethe [runtimecompilationsampleonGitHub](https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/runtimecompilation) for a sample that shows making runtime compilation work across projects.
Build- and publish-time compilation of Razor files is enabled by default by the Razor SDK. When enabled, runtime compilation complements build-time compilation, allowing Razor files to be updated if they are edited.
@@ -55,15 +131,15 @@ To enable runtime compilation based on the environment and configuration mode:
55
131
56
132
1. Updatetheproject's `Startup.ConfigureServices` method to include a call to `AddRazorRuntimeCompilation`. Conditionally execute `AddRazorRuntimeCompilation` such that it only runs in Debug mode when the `ASPNETCORE_ENVIRONMENT` variable is set to `Development`:
*Seethe [runtimecompilationsampleonGitHub](https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/runtimecompilation) for a sample that shows making runtime compilation work across projects.
142
+
*Seethe [runtimecompilationsampleonGitHub](https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/runtimecompilation) for a sample that shows making runtime compilation work across projects.
0 commit comments