.NET Core 3.0及ASP.NET Core 3.0 前瞻

.NET Core 3.0及ASP.NET Core 3.0 前瞻,第1张

概述前几天微软发布了 .NET Core 3.0 Preview 9 ,这是.NET Core 3.0 最后一个预览版。 .NET Core 3.0 正式发布将在.NET Conf 上发布,.NET Conf 时间是9月23日至25日。 Visual Studio 2019 16.3预览版3和Visual Studio for Mac 8.3支持.NET Core 3.0 ,这些版本也同时发布。 从.

前几天微软发布了 .NET Core 3.0 PrevIEw 9 ,这是.NET Core 3.0 最后一个预览版。

.NET Core 3.0 正式发布将在.NET Conf 上发布,.NET Conf 时间是9月23日至25日。

Visual Studio 2019 16.3预览版3和Visual Studio for Mac 8.3支持.NET Core 3.0 ,这些版本也同时发布。

从.NET Core 3.0 PrevIEw 7就可用于生产,目前dotnet官网就是使用 https://dotnet.microsoft.com/ Powered by .NET Core 3.0.0-prevIEw9-19423-09。

博客园也在前些天升级为.NET Core 3.0 PrevIEw 8,目前运行算是良好。

下面实际体验.NET Core 3.0 新特性。

.NET Core 3.0 System.Text.Json

示例:

    public class Person    {        public string Firstname { get; set; }        public string Lastname { get; set; }        public DateTime? BirthDay { get; set; }    }    //转成对象    string Json = ...    Person person = JsonSerializer.Parse<Person>(Json);        //转成Json字符串    Person person = ...    string Json = JsonSerializer.ToString(person);

.NET Standard 2.1

要以.NET Standard 2.1为目标,必须编辑项目文件并将TargetFramework属性更改为netstandard2.1: .NET Framework不支持.NET Standard 2.1。

<Project Sdk="Microsoft.NET.Sdk">   <PropertyGroup>    <TargetFramework>netstandard2.1</TargetFramework>  </PropertyGroup> </Project>

 

Microsoft.Data.sqlClIEnt

Microsoft.Data.sqlClIEnt是Microsoft sql Server的数据提供程序。

它是两个System.Data.sqlClIEnt组件的联合体,独立存在于.NET Framework和.NET Core中。

最新版本安装

Install-Package Microsoft.Data.sqlClIEnt 

https://github.com/dotnet/sqlClIEnt 

发布成单个程序

dotnet publish -r win10-x64 /p:PublishSinglefile=true

Alpine Docker images

.NET Core and ASP.NET Core on ARM64

docker pull mcr.microsoft.com/dotnet/core/runtime:3.0-alpine-arm64v8 

docker pull mcr.microsoft.com/dotnet/core/aspnet:3.0-alpine-arm64v8

dotnet-counters

安装 : dotnet tool install --global dotnet-counters --version 3.0.0-prevIEw8.19412.1

使用示例:

显示所有信息

dotnet-counters monitor --process-ID 1902 System.Runtime

显示cpu使用 GC 及异常数

dotnet-counters monitor --process-ID 1902 System.Runtime[cpu-usage,gc-heap-size,exception-count]

官方文档:https://github.com/dotnet/diagnostics/blob/master/documentation/dotnet-counters-instructions.md

ReadyToRun

你可以通过将应用程序集编译为ReadyToRun(R2R)格式来缩短.NET Core应用程序的启动时间。R2R是一种提前(AOT)编译的形式。

示例提升:

仅限IL的应用:
启动时间:1.9秒 内存使用量:69.1 MB 应用程序大小:150 MB 使用ReadyToRun图像:
启动时间:1.3秒。 内存使用量:55.7 MB 应用程序大小:156 MB

要启用ReadyToRun编译 需要以下 *** 作:

将PublishReadyToRun属性设置为true。 使用显式发布RuntimeIDentifIEr。

<Project Sdk="Microsoft.NET.Sdk">  <PropertyGroup>    <OutputType>Exe</OutputType>    <TargetFramework>netcoreapp3.0</TargetFramework>    <PublishReadyToRun>true</PublishReadyToRun>  </PropertyGroup></Project>

 

dotnet publish -r win-x64 -c Release

ReadyToRun编译器目前不支持交叉定位。需要在给定目标上进行编译。例如,如果想要windows x64的R2R程序,则需要在该环境中运行publish命令。

IL linker

使用IL linker 可以将程序大小从大约68MB减少到大约28MB

dotnet publish -r win10-x64 -c Release /p:PublishTrimmed=true /p:PublishSinglefile=true

httpClIEnt支持http/2

使用示例:

var clIEnt = new httpClIEnt() { BaseAddress = new Uri("https://localhost:5001") };// http/1.1 requestusing (var response = await clIEnt.GetAsync("/")){    Console.Writeline(response.Content);}// http/2 requestusing (var request = new httpRequestMessage(httpMethod.Get,"/") { Version = new Version(2,0) })using (var response = await clIEnt.SendAsync(request)){    Console.Writeline(response.Content);}

 

ASP.NET Core 3.0

前一篇也有介绍ASP.NET Core 3.0预览版体验。

ASP.NET Core 3.0中主要更新还是Blazor和gRPC

Blazor

Blazor 是一个用于使用 .NET 生成交互式客户端 Web UI 的框架:

使用 C# 代替 JavaScript 来创建丰富的交互式 UI。 共享使用 .NET 编写的服务器端和客户端应用逻辑。 将 UI 呈现为 HTML 和 CSS,以支持众多浏览器,其中包括移动浏览器。

使用 .NET 进行客户端 Web 开发可提供以下优势:

使用 C# 代替 JavaScript 来编写代码。 利用现有的 .NET 库生态系统。 在服务器和客户端之间共享应用逻辑。 受益于 .NET 的性能、可靠性和安全性。 始终高效支持 windows、linux 和 macOS 上的 Visual Studio。 以一组稳定、功能丰富且易用的通用语言、框架和工具为基础来进行生成。

Blazor 应用基于组件 。 Blazor 中的组件是指 UI 元素,例如,页面、对话框或数据输入窗体。

组件类通常以 Razor 标记页(文件扩展名为 .razor )的形式编写。 Blazor 中的组件有时被称为 Razor 组件 。

Razor 标记演示组件:

<div>    <h1>@Title</h1>    @ChildContent    <button @onclick="OnYes">Yes!</button></div>@code {    [Parameter]    public string Title { get; set; }    [Parameter]    public RenderFragment ChildContent { get; set; }    private voID OnYes()    {        Console.Writeline("Write to the console in C#! ‘Yes‘ button was selected.From lineZero");    }

对话框的正文内容 (ChildContent) 和标题 (Title) 由在其 UI 中使用此组件的组件提供。 OnYes 是由按钮的 onclick 事件触发的 C# 方法。

Blazor 使用 UI 构成的自然 HTML 标记。 HTML 元素指定组件,并且标记的特性将值传递给组件的属性。

在以下示例中,Index 组件中使用上面的 Dialog 组件。

@page "/"<h1>Hello,world!</h1>Welcome to your new app.<Dialog title="Blazor">    Do you want to <i>learn more</i> about Blazor?
   From lineZero
</Dialog>

更多官方介绍:https://docs.microsoft.com/zh-cn/aspnet/core/blazor/get-started?vIEw=aspnetcore-3.0&tabs=visual-studio

gRPC

gRPC 的主要优点是:

现代高性能轻量级 RPC 框架。 协定优先 API 开发,默认使用协议缓冲区,允许与语言无关的实现。 可用于多种语言的工具,以生成强类型服务器和客户端。 支持客户端、服务器和双向流式处理调用。 使用 Protobuf 二进制序列化减少对网络的使用。

这些优点使 gRPC 适用于:

效率至关重要的轻量级微服务。 需要多种语言用于开发的 polyglot 系统。 需要处理流式处理请求或响应的点对点实时服务。

虽然 C# 实现目前在官方 gRPC 上有介绍,但当前实现依赖于用 C (gRPC C-core) 编写的本机库。 

目前正在基于 Kestrel http 服务器和完全托管的 ASP.NET Core 实现gRPC。

时间:2019-09-23 21:44:23 阅读(5) 总结

以上是内存溢出为你收集整理的.NET Core 3.0及ASP.NET Core 3.0 前瞻全部内容,希望文章能够帮你解决.NET Core 3.0及ASP.NET Core 3.0 前瞻所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/1226642.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-06-05
下一篇 2022-06-05

发表评论

登录后才能评论

评论列表(0条)

保存