-
Notifications
You must be signed in to change notification settings - Fork 196
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge remote-tracking branch 'upstream/main' into features/cohost
- Loading branch information
Showing
84 changed files
with
1,363 additions
and
1,240 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# Razor Basics | ||
|
||
Razor is a templating language used in ASP.NET for creating dynamic web pages. It's not a programming language itself, but a markup syntax for embedding code (C# or VB.NET) into HTML. | ||
|
||
In a Razor file, you can use a combination of several languages: | ||
|
||
| Language | Usage | Supported in .NET Core and .NET 5+ | | ||
| --- | --- | --- | | ||
| **Razor syntax** | Used to embed and execute server-side code within HTML. | Yes | | ||
| **C#** | The server-side language used within Razor templates. Most commonly used with Razor. | Yes | | ||
| **HTML** | Used to structure the content on web pages. | Yes | | ||
| **JavaScript** | Used for client-side scripting in Razor templates. | Yes | | ||
| **CSS** | Used for styling web pages. | Yes | | ||
| **VB.NET** | Can be used in Razor syntax in the older .NET Framework. | No | | ||
|
||
Please note that while Razor syntax does support VB.NET in the older .NET Framework, VB.NET is not supported in .NET Core or .NET 5 and onwards. In these newer frameworks, only C# is supported. | ||
|
||
## Razor File Types | ||
|
||
Razor files typically come in three extensions: `.cshtml`, `.vbhtml`, and `.razor`. Each extension corresponds to a specific type of Razor file and determines its usage within an application: | ||
|
||
| File Extension | Type | Description | Usage | | ||
| --- | --- | --- | --- | | ||
| `.cshtml` | Razor View | Part of the MVC (Model-View-Controller) pattern, where the View is responsible for the presentation logic. Located within the Views folder of an MVC application and associated with a Controller. | Used in MVC applications for complex scenarios where separation of concerns is important. | | ||
| `.cshtml` | Razor Page | A page-based programming model that makes building web UI easier and more productive. Located within the Pages folder of a Razor Pages application and includes a `@page` directive at the top. | Used in Razor Pages applications for simpler scenarios where a full MVC model might be overkill. | | ||
| `.razor` | Razor Component (Blazor) | Used in Blazor, a framework for building interactive client-side web UI with .NET. Each `.razor` file is a self-contained component that can include both the markup and the processing logic. | Used in Blazor applications for building interactive client-side web UIs. | | ||
| `.vbhtml` | Razor View (VB.NET) | Part of the MVC (Model-View-Controller) pattern, where the View is responsible for the presentation logic. Located within the Views folder of an MVC application and associated with a Controller. | Used in older MVC applications written in VB.NET. | | ||
|
||
## Razor Editors: Legacy vs New | ||
|
||
| Aspect | Razor Legacy | Legacy .NET Core Razor Editor | New .NET Core Razor Editor | | ||
| --- | --- | --- | --- | | ||
| **Introduction** | Introduced with ASP.NET MVC 3. | Older Razor editor for ASP.NET Core projects. | Updated Razor editor introduced in Visual Studio 2019 version 16.8. | | ||
| **Usage** | Used in ASP.NET MVC and ASP.NET Web Pages applications. | Used for editing Razor views and pages in ASP.NET Core projects. | Used for editing Razor views and pages in ASP.NET Core projects. | | ||
| **Source code** | Closed source. | Closed source. | [Open source on GitHub](https://github.com/dotnet/razor/) | | ||
| **File Extensions** | `.cshtml` for C#, `.vbhtml` for VB.NET. | `.cshtml` and `.razor` | `.cshtml` and `.razor` | | ||
| **Functionality** | Creates dynamic web pages that combine HTML and server-side code. | Provides basic features like syntax highlighting and IntelliSense for Razor syntax. | Provides improved functionality and performance, including better IntelliSense, improved syntax highlighting, support for Razor formatting, better diagnostics, and features like "Go to Definition" and "Find All References" for Razor components and their parameters. | | ||
| **Support** | Supported for maintaining existing applications. | Phased out, not recommended for new projects. | Actively supported and recommended for new projects. | | ||
| **Configuration** | Used by default for .NET Framework applications. | The legacy .NET Core editor is off by default. | The new .NET Core editor is used by default. | | ||
| **Implementation** | Monolithic design, language services implemented by the editor, no LSP or TextMate grammars, limited VS integration. | Same as Razor Legacy | Uses LSP for language services, TextMate grammars for syntax highlighting, integrated with VS editor API, includes Blazor support. | | ||
|
||
## Razor Support Across ASP.NET Versions | ||
|
||
Different versions of ASP.NET support different features of Razor. Here's a summary: | ||
|
||
| TFM | Razor Support | | ||
| --- | --- | | ||
| **.NET Framework (<= 4.8)** | Supports Razor syntax with C# and VB.NET. Used in ASP.NET MVC and ASP.NET Web Pages applications. | | ||
| **.NET Core 1.x - 3.1** | Supports Razor syntax with C# only. Used in ASP.NET Core MVC, Razor Pages applications, and had preview support for Blazor. | | ||
| **.NET 5+** | Supports Razor syntax with C# only. Used in ASP.NET Core MVC, Razor Pages, and Blazor applications. | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
87 changes: 87 additions & 0 deletions
87
.../RazorSourceGeneratorComponentTests/ScriptTag_WithVariable/7/Shared_Component1_razor.g.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
#pragma checksum "Shared/Component1.razor" "{ff1816ec-aa5e-4d10-87f7-6f4963833460}" "b72b3eb93cc4a906714929a4849d9f7aac2ef62a" | ||
// <auto-generated/> | ||
#pragma warning disable 1591 | ||
namespace MyApp.Shared | ||
{ | ||
#line hidden | ||
using global::System; | ||
using global::System.Collections.Generic; | ||
using global::System.Linq; | ||
using global::System.Threading.Tasks; | ||
using global::Microsoft.AspNetCore.Components; | ||
public partial class Component1 : global::Microsoft.AspNetCore.Components.ComponentBase | ||
{ | ||
#pragma warning disable 1998 | ||
protected override void BuildRenderTree(global::Microsoft.AspNetCore.Components.Rendering.RenderTreeBuilder __builder) | ||
{ | ||
__builder.AddMarkupContent(0, "Component:\r\n"); | ||
#nullable restore | ||
#line 2 "Shared/Component1.razor" | ||
var msg = "What's up"; | ||
|
||
#line default | ||
#line hidden | ||
#nullable disable | ||
__builder.OpenElement(1, "script"); | ||
__builder.AddContent(2, "console.log(\'"); | ||
#nullable restore | ||
#line (3,23)-(3,26) 24 "Shared/Component1.razor" | ||
__builder.AddContent(3, msg); | ||
|
||
#line default | ||
#line hidden | ||
#nullable disable | ||
__builder.AddContent(4, "\');"); | ||
__builder.CloseElement(); | ||
__builder.AddMarkupContent(5, "\r\n"); | ||
__builder.OpenElement(6, "div"); | ||
__builder.AddContent(7, "console.log(\'"); | ||
#nullable restore | ||
#line (4,20)-(4,23) 24 "Shared/Component1.razor" | ||
__builder.AddContent(8, msg); | ||
|
||
#line default | ||
#line hidden | ||
#nullable disable | ||
__builder.AddContent(9, "\');"); | ||
__builder.CloseElement(); | ||
__builder.AddMarkupContent(10, "\r\n"); | ||
__builder.OpenElement(11, "script"); | ||
__builder.AddContent(12, "console.log(\'No variable\');"); | ||
__builder.CloseElement(); | ||
__builder.AddMarkupContent(13, "\r\n"); | ||
__builder.AddMarkupContent(14, "<div>console.log(\'No variable\');</div>\r\n"); | ||
__builder.OpenElement(15, "script"); | ||
__builder.AddMarkupContent(16, "\r\n console.log(\'"); | ||
#nullable restore | ||
#line (8,19)-(8,22) 25 "Shared/Component1.razor" | ||
__builder.AddContent(17, msg); | ||
|
||
#line default | ||
#line hidden | ||
#nullable disable | ||
__builder.AddMarkupContent(18, "\');\r\n"); | ||
__builder.CloseElement(); | ||
__builder.AddMarkupContent(19, "\r\n"); | ||
__builder.OpenElement(20, "div"); | ||
__builder.AddMarkupContent(21, "\r\n console.log(\'"); | ||
#nullable restore | ||
#line (11,19)-(11,22) 25 "Shared/Component1.razor" | ||
__builder.AddContent(22, msg); | ||
|
||
#line default | ||
#line hidden | ||
#nullable disable | ||
__builder.AddMarkupContent(23, "\');\r\n"); | ||
__builder.CloseElement(); | ||
__builder.AddMarkupContent(24, "\r\n"); | ||
__builder.OpenElement(25, "script"); | ||
__builder.AddMarkupContent(26, "\r\n console.log(\'No variable\');\r\n"); | ||
__builder.CloseElement(); | ||
__builder.AddMarkupContent(27, "\r\n"); | ||
__builder.AddMarkupContent(28, "<div>\r\n console.log(\'No variable\');\r\n</div>"); | ||
} | ||
#pragma warning restore 1998 | ||
} | ||
} | ||
#pragma warning restore 1591 |
Oops, something went wrong.