Net Core 2.0 Ecosystem
Read Catalogue
- Preface: A Reader's question (time by:2017.8.19)
- Project upgrade to ASP. NET Core 2.0
- What's NEW: Razor pages Introduction
- Template updates
- Entity Framework Core 2.0 provides DbContext pool
- Monitor, no code change configuration, Application monitor
- Razor support for C # 7.1
- Simplifies host configuration for Applications
- Summarize
ASP. 2.0 Release Date: August 14, 2017
Asp. NET Team announces the official release of ASP. 2.0, publishing visual Studio 2017 15.3 supports ASP. Razor Pages Project template.
Detailed release information view. NET Core 2.0.0 Release Notes documentation
Latest version of the SDK download: Https://dot.net/core
ASP. NET Core 2.0 provides a range of new features that make Web application development, publishing, deployment, and maintenance easier and framework performance further enhanced.
Introduction to the release of. NET Core 2.0, around 2.0 architecture, related articles in this series:
- . NET Core 2.0 ecosystem (1). NET Standard 2.0 feature Introduction and Usage Guide (published)
- . NET Core 2.0 ecosystem (2). NET Core 2.0 features Introduction and Usage Guide (published)
- . Net Core 2.0 Ecosystem (3) ASP. Introduction and Usage Guide (published)
- . Net Core 2.0 Ecosystem (4) Entity Framework Core 2.0 feature Introduction and Usage Guide (published)
Back to catalogue preface: Answer Reader's question (time by:2017.8.19)
Focus on the first two articles in the comments before you begin.
- Issue 1: update issues with tools
Question by @ Xuan 轅 Sword: Have you ever upgraded to a 15.3 update alone?
Answer by @yyww: Download the new version of the installer, more than 1M, will automatically update the
The VS2017 installer has been refactored into a modular installation, so for the 15.3 version of the update is an incremental update, the latest installer is downloaded and is automatically detected.
Visual Studio for MAC 7.1 also detects software updates and makes incremental updates.
- Question 2:what exactly is. NET standard?
Question by @wdwwtzy: This series is good, want to listen to what is the standard what is, suggest in depth, now too shallow
Question by @ Sky XM: How many architecture diagrams?
. NET Standard is a set of APIs that enables code sharing between. NET platforms that support. NET Standard, and a class library built on. NET code that can be reused in the. NET platform that supports. NET.
The currently supported platforms for. NET Standard 2.0 are:
- . NET Framework 4.6.1
- . NET Core 2.0
- Mono 5.4
- Xamarin.ios 10.14
- Xamarin.mac 3.8
- Xamarin.android 7.5
- UWP (expected to be released in the second half of 2017)
In a little deeper, look at this picture
platform to. NET Standard support table (by @ Farm code lifetime)
Figure
- Question 3: is the System.Drawing API available?
Problem by @PowerShell freeware: the. NET Core2 is the official version, adding System.Drawing.
Did someone successfully run the previous WinForm program on top? Can someone please give me a try?
The namespace System.Drawing is added, only provides the struct, and does not provide a drawing class, which is believed to be supported in the next release.
Back to Catalog item upgrade to ASP. NET Core 2.0
ASP. NET Core 2.0 can be run simultaneously in the .NET Framework 4.6.1
and .NET Core 2.0
framework, changing the project target framework to:netcoreapp2.0
<PropertyGroup><TargetFramework>netcoreapp2.0</TargetFramework></PropertyGroup>
Project properties can be set in visual stdio
You can also manually edit the project file to upgrade the reference package in the original project Microsoft.AspNetCore.*
to 2.0
<itemgroup>< packagereference include= " Microsoft.AspNetCore.All "version=" 2.0.0 "/> <packagereference Include= "Microsoft.Extensions.Logging.Debug" version= " 2.0.0 "/><packagereference Include= "Microsoft.VisualStudio.Web.BrowserLink" version=" 2.0.0 "/></ITEMGROUP>
The ASP. NET Core 2.0 project is optimized for publishing files that contain only referenced class libraries. This optimization helps make the publishing process smoother and easier to distribute Web applications.
See this article to upgrade the ASP. NET Core 1.0 to 2.0 details.
Back to catalog new features: Razor pages Introduction
in ASP. NET Core 2.0, it provides a new way of encoding, which is simpler than using MVC architecture in a scene in a logical set of pages.
Razor pages is a page-first architecture that allows users to develop an interface using a simple server-side interaction that interacts with the page model object, without requiring a controller to relay.
In the project startup file, add the code
public class Startup{ public void ConfigureServices(IServiceCollection services) { // 包含对Razor Pages 和控制器支持. services.AddMvc(); } public void Configure(IApplicationBuilder app) { app.UseMvc(); }}
The Razor pages feature is activated when the Addmvc method is called in service registration.
Add a test page, placed in the pages directory, named Now.cshtml
.
@page<html> <body> <h2>The server-local time now is:</h2> <p>@DateTime.Now</p> </body></html>
This looks like a standard razor view, just adding markup at the top of the page, @page
defining the page as a standalone Razor page that can still use htmlhelpers, Taghelpers, or. NET code in the page. You can define a method as you would in the Razor view, simply add a block-level element and @functions
then write code inside it.
@page@functions {public string FormatDate(DateTime theTime) { return theTime.ToString("d");}}<body> <p>@FormatDate(DateTime.Now)</p> </body>
Using the Pagemodel object together, you can create more complex page interactions, Pagemodel is an MVVM schema concept that is equivalent to a view model (VM), allows methods to be executed, and binds properties to the corresponding page. Create a class in the pages directory NowModel.cshtml.cs
.
Namespacemyfirstrazorpage.pages{public Class nowmodel: pagemodel{private Ifileprovider _fileprovider; public NowModel (physicalfileprovider fileprovider) {_fileprovider = Fileprovider; LastModified = _fileprovider.getfileinfo ( "pages/now.cshtml"). Lastmodified.localdatetime; } public DateTime lastmodified {get; set;} public void onget () {}}}
This class inherits from Pagemodel, which can build logical classes that interact with the page according to the business needs of the page, and can unit test the business logic in the class. In this example, the LastModified property is loaded into the page. Also note that the OnGet
method is used to declare that Pagemodel can respond to HTTP GET requests.
Update Razor Page, using the LastModified property defined by Pagemodel.
@page
@model MyFirstRazorPage.Pages.NowModel
<html> <body> <h2>This page was last updated:</h2> <p>@Model.LastModified</p> </body></html>
More Razor pages refer to the information in more detail.
Back to Catalog Template update
Templates have been enhanced to include not only the MVC Pattern Web Application template, but also the Razor Pages Web Application template, as well as a series of single-page application (SPA) program templates. These single-page templates use the JavaScript service feature to embed Nodejs in an ASP. NET Core service and compile the JavaScript application Server as part of the project.
Built-in project templates provided by the command-line tool
Back to Catalog Entity Framework Core 2.0 provides DbContext pool
See: Entity Framework Core 2.0 release (released later, summarized in a separate article)
Back to directory Monitor, no code change configuration, Application monitor
The ASP. NET Core 2.0 projects that run on Azure app service do not need to be modified to provide performance analysis, error reporting, and azure application monitoring capabilities.
In Visual Studio 2017, right-click the project, Add->application Insights Telemetry, start Application Data collection, and then you can preview the log information and the application performance report directly.
This feature allows us to test and respond to application performance during the development phase, and when the program is published to Azure, it can be analyzed and debugged in the Azure portal, and the collection of program information begins when the application is first published and navigated to the cloud portal. Azure will prompt you with a purple banner, which indicates that the application monitoring and analysis features are available.
Click to view the Application monitoring service without recompiling and deploying, and the application monitoring service will begin to report the captured activity data.
The data report shows the number of failed requests and errors in the application. Click on the data item you are interested in to show more information about the failed request:
System.Exception
, click View Exception Report to see the details of the thrown exception, including the call stack:
Snapshot debugging for application monitoring now supports ASP. NET Core 2.0 applications. If you configure snapshot debugging in your application, the open Debug Snapshot link at the top displays and displays the full call stack, and you can click a method in the stack to view the local variables:
All right! We can go a step further by clicking the Download Snapshot button in the upper-right corner to launch an exception debugging session in Visual Studio.
How is the performance of these pages? From the Application Monitoring page, select performance options on the left to delve into the performance tracking of each request in the application.
For more information, see Performance analysis using Application insights.
If you want to use the original log of your application, you can enable diagnostic logging in application services and set the diagnostic level to warning or error to see that the exception is thrown.
Finally, select the log stream on the left, and you can see the consoles that you have on the developer workstation. Select the severity level or greater level of error and log messages that will be triggered in azure.
All application-aware functionality can be used in ASP. NET Core without recompiling and deploying. Snapshot debugging requires adding additional steps and some code, and configuration is as simple as adding extra code to the startup class.
Update information see: Application Insight online Documentation
Back to Catalog Razor Support C # 7.1
The Razor view engine supports C # 7.1 features with the Roslyn compiler, such as: Default expressions, inferred tuple names, and pattern-matching generics. To use the C # 7.1 attribute in your project, add the following properties to the project file and then reload the solution:
<LangVersion>latest</LangVersion>
C # 7.1 is itself a preview state, and you can see the language specifications for those features in its GitHub repository.
Back to the directory simplifying the application's host configuration
Host configuration has been greatly simplified, provided in the default ASP. NET Core project template WebHost.CreateDefaultBuilder
, automatically assigned an Kestrel server, if IIS is available, try to run on IIS, and configure the standard console log provider.
public class Program{ public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build();}
Back to catalog Summary
The new set of features from ASP. NET Core 2.0 provides a new way to write applications that simplifies the management and maintenance of your applications in the production environment.
Net Core 2.0 Eco 1