Skip to content

Commit 5af1616

Browse files
authored
Merge pull request #17781 from dotnet/master
Update live with master
2 parents fbdb8b9 + 9f9bd9a commit 5af1616

18 files changed

Lines changed: 611 additions & 98 deletions

aspnetcore/data/ef-rp/read-related-data.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,8 @@ The following code loads related data with the `Select` method:
132132

133133
[!code-csharp[](intro/samples/cu30snapshots/6-related/Pages/Courses/IndexSelect.cshtml.cs?name=snippet_RevisedIndexMethod&highlight=6)]
134134

135+
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).
136+
135137
The `CourseViewModel`:
136138

137139
[!code-csharp[](intro/samples/cu30snapshots/6-related/Models/SchoolViewModels/CourseViewModel.cs?name=snippet)]

aspnetcore/fundamentals/routing.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -449,6 +449,8 @@ Using a template is generally the simplest approach to routing. Constraints and
449449
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.
450450
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.
451451

452+
[!INCLUDE[](~/includes/regex.md)]
453+
452454
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:
453455

454456
* The first literal, right to left, is `c`. So `/abcd` is searched from right and finds `/ab|c|d`.

aspnetcore/mvc/controllers/routing.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ The `RouteTokenTransformerConvention` is registered as an option in `ConfigureSe
524524

525525
See [MDN web docs on Slug](https://developer.mozilla.org/docs/Glossary/Slug) for the definition of Slug.
526526

527+
[!INCLUDE[](~/includes/regex.md)]
527528
<a name="routing-multiple-routes-ref-label"></a>
528529

529530
### Multiple attribute routes

aspnetcore/mvc/controllers/routing/samples/3.x/main/StartupSlugifyParamTransformer.cs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using Microsoft.Extensions.Configuration;
66
using Microsoft.Extensions.DependencyInjection;
77
using Microsoft.Extensions.Hosting;
8+
using System;
89
using System.Text.RegularExpressions;
910

1011
namespace WebMvcRouting
@@ -63,9 +64,11 @@ public string TransformOutbound(object value)
6364
{
6465
if (value == null) { return null; }
6566

66-
// Slugify value
6767
return Regex.Replace(value.ToString(),
68-
"([a-z])([A-Z])", "$1-$2").ToLowerInvariant();
68+
"([a-z])([A-Z])",
69+
"$1-$2",
70+
RegexOptions.CultureInvariant,
71+
TimeSpan.FromMilliseconds(100)).ToLowerInvariant();
6972
}
7073
}
7174
#endregion

aspnetcore/mvc/views/view-compilation.md

Lines changed: 81 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,20 +4,96 @@ author: rick-anderson
44
description: Learn how compilation of Razor files occurs in an ASP.NET Core app.
55
ms.author: riande
66
ms.custom: mvc
7-
ms.date: 4/8/2020
7+
ms.date: 04/13/2020
88
uid: mvc/views/view-compilation
99
---
1010
# Razor file compilation in ASP.NET Core
1111

1212
By [Rick Anderson](https://twitter.com/RickAndMSFT)
1313

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:
49+
50+
```csharp
51+
public void ConfigureServices(IServiceCollection services)
52+
{
53+
services.AddRazorPages()
54+
.AddRazorRuntimeCompilation();
55+
56+
// code omitted for brevity
57+
}
58+
```
59+
60+
## Conditionally enable runtime compilation in an existing project
61+
62+
Runtime compilation can be enabled such that it's only available for local development. Conditionally enabling in this manner ensures that the published output:
63+
64+
* Uses compiled views.
65+
* Doesn't enable file watchers in production.
66+
67+
To enable runtime compilation only in the Development environment:
68+
69+
1. Install the [Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation/) NuGet package.
70+
1. Modify the launch profile `environmentVariables` section in *launchSettings.json*:
71+
* Verify `ASPNETCORE_ENVIRONMENT` is set to `"Development"`.
72+
* Set `ASPNETCORE_HOSTINGSTARTUPASSEMBLIES` to `"Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation"`.
73+
74+
In the following example, runtime compilation is enabled in the Development environment for the `IIS Express` and `RazorPagesApp` launch profiles:
75+
76+
[!code-json[](~/mvc/views/view-compilation/samples/3.1/launchSettings.json?highlight=15-16,24-25)]
77+
78+
No code changes are needed in the project'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.
79+
80+
## Additional resources
81+
82+
* [RazorCompileOnBuild and RazorCompileOnPublish](xref:razor-pages/sdk#properties) properties.
83+
* <xref:razor-pages/index>
84+
* <xref:mvc/views/overview>
85+
* <xref:razor-pages/sdk>
86+
* See the [runtime compilation sample on GitHub](https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/runtimecompilation) for a sample that shows making runtime compilation work across projects.
87+
88+
::: moniker-end
89+
90+
::: moniker range="= aspnetcore-3.0"
1591

1692
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 application.
1793

1894
## Razor compilation
1995

20-
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.
96+
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.
2197

2298
## Runtime compilation
2399

@@ -55,15 +131,15 @@ To enable runtime compilation based on the environment and configuration mode:
55131

56132
1. Update the project'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`:
57133

58-
[!code-csharp[](~/mvc/views/view-compilation/sample/Startup.cs?name=snippet)]
134+
[!code-csharp[](~/mvc/views/view-compilation/samples/3.0/Startup.cs?name=snippet)]
59135

60136
## Additional resources
61137

62138
* [RazorCompileOnBuild and RazorCompileOnPublish](xref:razor-pages/sdk#properties) properties.
63139
* <xref:razor-pages/index>
64140
* <xref:mvc/views/overview>
65141
* <xref:razor-pages/sdk>
66-
* See the [runtimecompilation sample on GitHub](https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/runtimecompilation) for a sample that shows making runtime compilation work across projects.
142+
* See the [runtime compilation sample on GitHub](https://github.com/aspnet/samples/tree/master/samples/aspnetcore/mvc/runtimecompilation) for a sample that shows making runtime compilation work across projects.
67143
68144
::: moniker-end
69145

Binary file not shown.

aspnetcore/mvc/views/view-compilation/sample/DotNetFrameworkProject.csproj

Lines changed: 0 additions & 19 deletions
This file was deleted.

aspnetcore/mvc/views/view-compilation/sample/MvcRazorCompileOnPublish.csproj

Lines changed: 0 additions & 12 deletions
This file was deleted.

aspnetcore/mvc/views/view-compilation/sample/RuntimeCompilation.csproj

Lines changed: 0 additions & 9 deletions
This file was deleted.

aspnetcore/mvc/views/view-compilation/sample/Startup.cs renamed to aspnetcore/mvc/views/view-compilation/samples/3.0/Startup.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,4 +53,4 @@ public void Configure(IApplicationBuilder app)
5353
});
5454
}
5555
}
56-
#endregion
56+
#endregion

0 commit comments

Comments
 (0)