From 404adf0a590a6f48d77666185240f097f0798fbb Mon Sep 17 00:00:00 2001 From: Alexander Wicht Date: Fri, 30 Sep 2022 19:40:43 +0200 Subject: [PATCH] Updates note for enabling emission of Razor generated files. Fixes #26804 --- aspnetcore/mvc/views/razor.md | 52 +++++++---------------------------- 1 file changed, 10 insertions(+), 42 deletions(-) diff --git a/aspnetcore/mvc/views/razor.md b/aspnetcore/mvc/views/razor.md index d87f9c3b72..843c47250b 100644 --- a/aspnetcore/mvc/views/razor.md +++ b/aspnetcore/mvc/views/razor.md @@ -903,10 +903,10 @@ Rendered output: There are three directives that pertain to [Tag Helpers](xref:mvc/views/tag-helpers/intro). -| Directive | Function | -| --------- | -------- | -| [`@addTagHelper`](xref:mvc/views/tag-helpers/intro#add-helper-label) | Makes Tag Helpers available to a view. | -| [`@removeTagHelper`](xref:mvc/views/tag-helpers/intro#remove-razor-directives-label) | Removes Tag Helpers previously added from a view. | +| Directive | Function | +| ------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------ | +| [`@addTagHelper`](xref:mvc/views/tag-helpers/intro#add-helper-label) | Makes Tag Helpers available to a view. | +| [`@removeTagHelper`](xref:mvc/views/tag-helpers/intro#remove-razor-directives-label) | Removes Tag Helpers previously added from a view. | | [`@tagHelperPrefix`](xref:mvc/views/tag-helpers/intro#prefix-razor-directives-label) | Specifies a tag prefix to enable Tag Helper support and to make Tag Helper usage explicit. | ## Razor reserved keywords @@ -948,45 +948,13 @@ C# Razor keywords must be double-escaped with `@(@C# Razor Keyword)` (for exampl ## Inspect the Razor C# class generated for a view -The [Razor SDK](xref:razor-pages/sdk) handles compilation of Razor files. When building a project, the Razor SDK generates an `obj///Razor` directory in the project root. The directory structure within the `Razor` directory mirrors the project's directory structure. - -Consider the following directory structure in an ASP.NET Core Razor Pages project: - +The [Razor SDK](xref:razor-pages/sdk) handles compilation of Razor files. By default, the generated code files are not emitted in recent versions of ASP.NET Core. To enable this, set the `EmitCompilerGeneratedFiles` directive in your `.csproj` file to `true`: +```xml + + true + ``` - Areas/ - Admin/ - Pages/ - Index.cshtml - Index.cshtml.cs - Pages/ - Shared/ - _Layout.cshtml - _ViewImports.cshtml - _ViewStart.cshtml - Index.cshtml - Index.cshtml.cs - ``` - -Building the project in *Debug* configuration yields the following `obj` directory: - -``` - obj/ - Debug/ - netcoreapp2.1/ - Razor/ - Areas/ - Admin/ - Pages/ - Index.g.cshtml.cs - Pages/ - Shared/ - _Layout.g.cshtml.cs - _ViewImports.g.cshtml.cs - _ViewStart.g.cshtml.cs - Index.g.cshtml.cs -``` - -To view the generated class for `Pages/Index.cshtml`, open `obj/Debug/netcoreapp2.1/Razor/Pages/Index.g.cshtml.cs`. +When building the project, the Razor SDK generates an `obj//net6.0/generated/` directory in the project root. Its subdirectory contains the emitted Razor page code files. ## View lookups and case sensitivity