commit
9a46e78c79
|
@ -2,121 +2,25 @@
|
|||
title: Razor file compilation in ASP.NET Core
|
||||
author: rick-anderson
|
||||
description: Learn how compilation of Razor files occurs in an ASP.NET Core app.
|
||||
monikerRange: '>= aspnetcore-1.1'
|
||||
ms.author: riande
|
||||
ms.custom: mvc
|
||||
ms.date: 12/05/2019
|
||||
ms.date: 4/8/2020
|
||||
uid: mvc/views/view-compilation
|
||||
---
|
||||
# Razor file compilation in ASP.NET Core
|
||||
|
||||
By [Rick Anderson](https://twitter.com/RickAndMSFT)
|
||||
|
||||
::: moniker range="= aspnetcore-1.1"
|
||||
|
||||
A Razor file is compiled at runtime, when the associated MVC view is invoked. Build-time Razor file publishing is unsupported. Razor files can optionally be compiled at publish time and deployed with the app—using the precompilation tool.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0"
|
||||
|
||||
A Razor file is compiled at runtime, when the associated Razor Page or MVC view is invoked. Build-time Razor file publishing is unsupported. Razor files can optionally be compiled at publish time and deployed with the app—using the precompilation tool.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.1 <= aspnetcore-2.2"
|
||||
|
||||
A Razor file is compiled at runtime, when the associated Razor Page or MVC view is invoked. Razor files are compiled at both build and publish time using the [Razor SDK](xref:razor-pages/sdk).
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-3.0"
|
||||
|
||||
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.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
## Razor compilation
|
||||
|
||||
::: moniker range=">= aspnetcore-3.0"
|
||||
|
||||
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.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.1 <= aspnetcore-2.2"
|
||||
|
||||
Build- and publish-time compilation of Razor files is enabled by default by the Razor SDK. Editing Razor files after they're updated is supported at build time. By default, only the compiled *Views.dll* and no *.cshtml* files or references assemblies required to compile Razor files are deployed with your app.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The precompilation tool has been deprecated, and will be removed in ASP.NET Core 3.0. We recommend migrating to [Razor Sdk](xref:razor-pages/sdk).
|
||||
>
|
||||
> The Razor SDK is effective only when no precompilation-specific properties are set in the project file. For instance, setting the *.csproj* file's `MvcRazorCompileOnPublish` property to `true` disables the Razor SDK.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0"
|
||||
|
||||
If your project targets .NET Framework, install the [Microsoft.AspNetCore.Mvc.Razor.ViewCompilation](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/) NuGet package:
|
||||
|
||||
[!code-xml[](view-compilation/sample/DotNetFrameworkProject.csproj?name=snippet_ViewCompilationPackage)]
|
||||
|
||||
If your project targets .NET Core, no changes are necessary.
|
||||
|
||||
The ASP.NET Core 2.x project templates implicitly set the `MvcRazorCompileOnPublish` property to `true` by default. Consequently, this element can be safely removed from the *.csproj* file.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The precompilation tool has been deprecated, and will be removed in ASP.NET Core 3.0. We recommend migrating to [Razor Sdk](xref:razor-pages/sdk).
|
||||
>
|
||||
> Razor file precompilation is unavailable when performing a [self-contained deployment (SCD)](/dotnet/core/deploying/#self-contained-deployments-scd) in ASP.NET Core 2.0.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-1.1"
|
||||
|
||||
Set the `MvcRazorCompileOnPublish` property to `true`, and install the [Microsoft.AspNetCore.Mvc.Razor.ViewCompilation](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Razor.ViewCompilation/) NuGet package. The following *.csproj* sample highlights these settings:
|
||||
|
||||
[!code-xml[](view-compilation/sample/MvcRazorCompileOnPublish.csproj?highlight=4,10)]
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="<= aspnetcore-2.0"
|
||||
|
||||
Prepare the app for a [framework-dependent deployment](/dotnet/core/deploying/#framework-dependent-deployments-fdd) with the [.NET Core CLI publish command](/dotnet/core/tools/dotnet-publish). For example, execute the following command at the project root:
|
||||
|
||||
```dotnetcli
|
||||
dotnet publish -c Release
|
||||
```
|
||||
|
||||
A *\<project_name>.PrecompiledViews.dll* file, containing the compiled Razor files, is produced when precompilation succeeds. For example, the screenshot below depicts the contents of *Index.cshtml* within *WebApplication1.PrecompiledViews.dll*:
|
||||
|
||||
![Razor views inside DLL](view-compilation/_static/razor-views-in-dll.png)
|
||||
|
||||
::: moniker-end
|
||||
|
||||
## Runtime compilation
|
||||
|
||||
::: moniker range="= aspnetcore-2.1"
|
||||
|
||||
Build-time compilation is supplemented by runtime compilation of Razor files. ASP.NET Core MVC will recompile Razor files when the contents of a *.cshtml* file change.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.2"
|
||||
|
||||
Build-time compilation is supplemented by runtime compilation of Razor files. The <xref:Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions> <xref:Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions.AllowRecompilingViewsOnFileChange> gets or sets a value that determines if Razor files (Razor views and Razor Pages) are recompiled and updated if files change on disk.
|
||||
|
||||
The default value is `true` for:
|
||||
|
||||
* If the app's compatibility version is set to <xref:Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_1> or earlier
|
||||
* If the app's compatibility version is set to <xref:Microsoft.AspNetCore.Mvc.CompatibilityVersion.Version_2_2> or later and the app is in the Development environment <xref:Microsoft.AspNetCore.Hosting.HostingEnvironmentExtensions.IsDevelopment*>. In other words, Razor files wouldn't recompile in non-Development environment unless <xref:Microsoft.AspNetCore.Mvc.Razor.RazorViewEngineOptions.AllowRecompilingViewsOnFileChange> is explicitly set.
|
||||
|
||||
For guidance and examples of setting the app's compatibility version, see <xref:mvc/compatibility-version>.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-3.0"
|
||||
|
||||
To enable runtime compilation for all environments and configuration modes:
|
||||
|
||||
1. Install the [Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation](https://www.nuget.org/packages/Microsoft.AspNetCore.Mvc.Razor.RuntimeCompilation/) NuGet package.
|
||||
|
@ -169,27 +73,35 @@ To enable runtime compilation based on the environment and configuration mode:
|
|||
}
|
||||
```
|
||||
|
||||
::: moniker-end
|
||||
|
||||
## Additional resources
|
||||
|
||||
::: moniker range="= aspnetcore-1.1"
|
||||
|
||||
* <xref:mvc/views/overview>
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="= aspnetcore-2.0"
|
||||
|
||||
* <xref:razor-pages/index>
|
||||
* <xref:mvc/views/overview>
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range=">= aspnetcore-2.1"
|
||||
|
||||
* <xref:razor-pages/index>
|
||||
* <xref:mvc/views/overview>
|
||||
* <xref:razor-pages/sdk>
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="< aspnetcore-3.0"
|
||||
|
||||
A Razor file is compiled at runtime, when the associated Razor Page or MVC view is invoked. Razor files are compiled at both build and publish time using the [Razor SDK](xref:razor-pages/sdk).
|
||||
|
||||
## Razor compilation
|
||||
|
||||
Build- and publish-time compilation of Razor files is enabled by default by the Razor SDK. Editing Razor files after they're updated is supported at build time. By default, only the compiled *Views.dll* and no *.cshtml* files or references assemblies required to compile Razor files are deployed with your app.
|
||||
|
||||
> [!IMPORTANT]
|
||||
> The precompilation tool has been deprecated, and will be removed in ASP.NET Core 3.0. We recommend migrating to [Razor Sdk](xref:razor-pages/sdk).
|
||||
>
|
||||
> The Razor SDK is effective only when no precompilation-specific properties are set in the project file. For instance, setting the *.csproj* file's `MvcRazorCompileOnPublish` property to `true` disables the Razor SDK.
|
||||
|
||||
## Runtime compilation
|
||||
|
||||
Build-time compilation is supplemented by runtime compilation of Razor files. ASP.NET Core MVC will recompile Razor files when the contents of a *.cshtml* file change.
|
||||
|
||||
## Additional resources
|
||||
|
||||
* <xref:razor-pages/index>
|
||||
* <xref:mvc/views/overview>
|
||||
* <xref:razor-pages/sdk>
|
||||
|
||||
::: moniker-end
|
|
@ -5,7 +5,7 @@ description: Overview of ASP.NET Core SignalR JavaScript client.
|
|||
monikerRange: '>= aspnetcore-2.1'
|
||||
ms.author: bradyg
|
||||
ms.custom: mvc
|
||||
ms.date: 11/12/2019
|
||||
ms.date: 04/08/2020
|
||||
no-loc: [SignalR]
|
||||
uid: signalr/javascript-client
|
||||
---
|
||||
|
@ -19,14 +19,18 @@ The ASP.NET Core SignalR JavaScript client library enables developers to call se
|
|||
|
||||
## Install the SignalR client package
|
||||
|
||||
The SignalR JavaScript client library is delivered as an [npm](https://www.npmjs.com/) package. If you're using Visual Studio, run `npm install` from the **Package Manager Console** while in the root folder. For Visual Studio Code, run the command from the **Integrated Terminal**.
|
||||
The SignalR JavaScript client library is delivered as an [npm](https://www.npmjs.com/) package. The following sections outline different ways to install the client library.
|
||||
|
||||
### Install with npm
|
||||
|
||||
If using Visual Studio, run the following commands from **Package Manager Console** while in the root folder. For Visual Studio Code, run the following commands from the **Integrated Terminal**.
|
||||
|
||||
::: moniker range=">= aspnetcore-3.0"
|
||||
|
||||
```console
|
||||
npm init -y
|
||||
npm install @microsoft/signalr
|
||||
```
|
||||
```bash
|
||||
npm init -y
|
||||
npm install @microsoft/signalr
|
||||
```
|
||||
|
||||
npm installs the package contents in the *node_modules\\@microsoft\signalr\dist\browser* folder. Create a new folder named *signalr* under the *wwwroot\\lib* folder. Copy the *signalr.js* file to the *wwwroot\lib\signalr* folder.
|
||||
|
||||
|
@ -34,23 +38,51 @@ npm installs the package contents in the *node_modules\\@microsoft\signalr\dist\
|
|||
|
||||
::: moniker range="< aspnetcore-3.0"
|
||||
|
||||
```console
|
||||
npm init -y
|
||||
npm install @aspnet/signalr
|
||||
```
|
||||
```bash
|
||||
npm init -y
|
||||
npm install @aspnet/signalr
|
||||
```
|
||||
|
||||
npm installs the package contents in the *node_modules\\@aspnet\signalr\dist\browser* folder. Create a new folder named *signalr* under the *wwwroot\\lib* folder. Copy the *signalr.js* file to the *wwwroot\lib\signalr* folder.
|
||||
|
||||
::: moniker-end
|
||||
|
||||
## Use the SignalR JavaScript client
|
||||
|
||||
Reference the SignalR JavaScript client in the `<script>` element.
|
||||
Reference the SignalR JavaScript client in the `<script>` element. For example:
|
||||
|
||||
```html
|
||||
<script src="~/lib/signalr/signalr.js"></script>
|
||||
```
|
||||
|
||||
### Use a Content Delivery Network (CDN)
|
||||
|
||||
To use the client library without the npm prerequisite, reference a CDN-hosted copy of the client library. For example:
|
||||
|
||||
```html
|
||||
<script src="https://cdnjs.cloudflare.com/ajax/libs/microsoft-signalr/3.1.3/signalr.min.js"></script>
|
||||
```
|
||||
|
||||
The client library is available on the following CDNs:
|
||||
|
||||
::: moniker range=">= aspnetcore-3.0"
|
||||
|
||||
* [cdnjs](https://cdnjs.com/libraries/microsoft-signalr)
|
||||
* [jsDelivr](https://www.jsdelivr.com/package/npm/@microsoft/signalr)
|
||||
* [unpkg](https://unpkg.com/@microsoft/signalr@next/dist/browser/signalr.min.js)
|
||||
|
||||
::: moniker-end
|
||||
|
||||
::: moniker range="< aspnetcore-3.0"
|
||||
|
||||
* [cdnjs](https://cdnjs.com/libraries/aspnet-signalr)
|
||||
* [jsDelivr](https://www.jsdelivr.com/package/npm/@aspnet/signalr)
|
||||
* [unpkg](https://unpkg.com/@aspnet/signalr@next/dist/browser/signalr.min.js)
|
||||
|
||||
::: moniker-end
|
||||
|
||||
### Install with LibMan
|
||||
|
||||
[LibMan](xref:client-side/libman/index) can be used to install specific client library files from the CDN-hosted client library. For example, only add the minified JavaScript file to the project. For details on that approach, see [Add the SignalR client library](xref:tutorials/signalr#add-the-signalr-client-library).
|
||||
|
||||
## Connect to a hub
|
||||
|
||||
The following code creates and starts a connection. The hub's name is case insensitive.
|
||||
|
|
|
@ -3,7 +3,7 @@ title: Create a .NET Core gRPC client and server in ASP.NET Core
|
|||
author: juntaoluo
|
||||
description: This tutorial shows how to create a gRPC Service and gRPC client on ASP.NET Core. Learn how to create a gRPC Service project, edit a proto file, and add a duplex streaming call.
|
||||
ms.author: johluo
|
||||
ms.date: 12/05/2019
|
||||
ms.date: 04/08/2020
|
||||
uid: tutorials/grpc/grpc-start
|
||||
---
|
||||
# Tutorial: Create a gRPC client and server in ASP.NET Core
|
||||
|
@ -292,7 +292,7 @@ info: Microsoft.AspNetCore.Hosting.Diagnostics[2]
|
|||
```
|
||||
|
||||
> [!NOTE]
|
||||
> The code in this article requires the ASP.NET Core HTTPS development certificate to secure the gRPC service. If the client fails with the message `The remote certificate is invalid according to the validation procedure.`, the development certificate is not trusted. For instructions to fix this issue, see [Trust the ASP.NET Core HTTPS development certificate on Windows and macOS](xref:security/enforcing-ssl#trust-the-aspnet-core-https-development-certificate-on-windows-and-macos).
|
||||
> The code in this article requires the ASP.NET Core HTTPS development certificate to secure the gRPC service. If the .NET gRPC client fails with the message `The remote certificate is invalid according to the validation procedure.` or `The SSL connection could not be established.`, the development certificate isn't trusted. To fix this issue, see [Call a gRPC service with an untrusted/invalid certificate](xref:grpc/troubleshoot#call-a-grpc-service-with-an-untrustedinvalid-certificate).
|
||||
|
||||
[!INCLUDE[](~/includes/gRPCazure.md)]
|
||||
|
||||
|
|
|
@ -85,7 +85,7 @@ At the end, you'll have a working chat app:
|
|||
|
||||
## Add the SignalR client library
|
||||
|
||||
The SignalR server library is included in the ASP.NET Core 3.0 shared framework. The JavaScript client library isn't automatically included in the project. For this tutorial, you use Library Manager (LibMan) to get the client library from *unpkg*. unpkg is a content delivery network (CDN)) that can deliver anything found in npm, the Node.js package manager.
|
||||
The SignalR server library is included in the ASP.NET Core 3.0 shared framework. The JavaScript client library isn't automatically included in the project. For this tutorial, you use Library Manager (LibMan) to get the client library from *unpkg*. unpkg is a content delivery network (CDN) that can deliver anything found in npm, the Node.js package manager.
|
||||
|
||||
# [Visual Studio](#tab/visual-studio/)
|
||||
|
||||
|
@ -317,7 +317,7 @@ At the end, you'll have a working chat app:
|
|||
|
||||
## Add the SignalR client library
|
||||
|
||||
The SignalR server library is included in the `Microsoft.AspNetCore.App` metapackage. The JavaScript client library isn't automatically included in the project. For this tutorial, you use Library Manager (LibMan) to get the client library from *unpkg*. unpkg is a content delivery network (CDN)) that can deliver anything found in npm, the Node.js package manager.
|
||||
The SignalR server library is included in the `Microsoft.AspNetCore.App` metapackage. The JavaScript client library isn't automatically included in the project. For this tutorial, you use Library Manager (LibMan) to get the client library from *unpkg*. unpkg is a content delivery network (CDN) that can deliver anything found in npm, the Node.js package manager.
|
||||
|
||||
# [Visual Studio](#tab/visual-studio/)
|
||||
|
||||
|
|
Loading…
Reference in New Issue