{"id":10016,"date":"2017-08-14T09:01:14","date_gmt":"2017-08-14T16:01:14","guid":{"rendered":"https:\/\/blogs.msdn.microsoft.com\/webdev\/?p=10016"},"modified":"2021-11-01T03:52:18","modified_gmt":"2021-11-01T10:52:18","slug":"announcing-asp-net-core-2-0","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/announcing-asp-net-core-2-0\/","title":{"rendered":"Announcing ASP.NET Core 2.0"},"content":{"rendered":"<p>The ASP.NET team is proud to announce general availability of ASP.NET Core 2.0.\u00a0 This release features compatibility with .NET Core 2.0, tooling support in Visual Studio 2017 version 15.3, and the new Razor Pages user-interface design paradigm.\u00a0 For a full list of updates, you can <a href=\"https:\/\/github.com\/dotnet\/core\/blob\/master\/release-notes\/2.0\/2.0.0.md\">read the release notes<\/a> and you can check the list of changed items in the <a href=\"https:\/\/github.com\/aspnet\/Announcements\/issues?q=is%3Aopen+is%3Aissue+label%3A2.0.0\">ASP.NET Announcements GitHub repository<\/a> for a list of changes from previous versions of ASP.NET Core.\u00a0 The latest SDK and tools can be downloaded from <a href=\"http:\/\/dot.net\/core\">https:\/\/dot.net\/core.<\/a> Read the <a href=\"https:\/\/aka.ms\/dotnetcore2announce\">.NET Core 2.0 release announcement<\/a> for more information and watch the launch video:<\/p>\n<div style=\"width: 100%; text-align: center;\">\n  <iframe width=\"560\" height=\"315\" src=\"https:\/\/channel9.msdn.com\/Blogs\/dotnet\/NET-Core-20-Released\/player\" allowfullscreen><\/iframe>\n<\/div>\n<p>\u00a0 With the ASP.NET Core 2.0 release we&#8217;ve added many new features to make building and monitoring web apps easier and we&#8217;ve worked hard to improve performance even more.\u00a0 More details about these features are available in our<\/p>\n<p><a href=\"https:\/\/blogs.msdn.microsoft.com\/webdev\/2017\/08\/25\/asp-net-core-2-0-features-1\/\">follow up post about ASP.NET Core features<\/a>.<\/p>\n<h2>Updating a Project to ASP.NET Core 2.0 ASP.NET Core 2.0 runs on both .NET Framework 4.6.1 and .NET Core 2.0, so you will need to update your target framework in your project to netcoreapp2.0 if you were previously targeting a 1.x version of .NET Core.<\/h2>\n<p> <figure id=\"attachment_10066\" aria-labelledby=\"figcaption_attachment_10066\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"size-full wp-image-10066\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/1-TargetFramework-1.png\" alt=\"Figure 1 - Setting Target Framework in Visual Studio 2017\" width=\"883\" height=\"176\" \/><figcaption id=\"figcaption_attachment_10066\" class=\"wp-caption-text\">Figure 1 &#8211; Setting Target Framework in Visual Studio 2017<\/figcaption><\/figure> Next, we recommend you reference the new Microsoft.AspNetCore.All metapackage instead of the collection of individual Microsoft.AspNetCore.* packages that you previously used.\u00a0 This new metapackage contains references to all of the AspNetCore packages and maintains a complete line-up of compatible packages.\u00a0 You can still include explicit references to specific Microsoft.AspNetCore.* package versions if you need one that is outside of the lineup, but our goal is to make this as simple a reference as possible.  What happens at publication time?\u00a0 We know that you don\u2019t want to publish the entire AspNetCore framework to your target environments, so the publish task now distributes only those libraries that you reference in your code.\u00a0 This tree-pruning step should help make your publish process much smoother and easier to distribute your web applications. More information about the features and changes you will need to address when migrating from <a href=\"https:\/\/docs.microsoft.com\/aspnet\/core\/migration\/1x-to-2x\/\">ASP.NET Core 1.x to 2.0 can be found in our documentation<\/a>.<\/p>\n<h2>Introducing Razor Pages With this release of ASP.NET Core, we are introducing a new coding paradigm that makes writing page-focused scenarios easier and simpler than our current Model-View-Controller architecture. \u00a0<\/h2>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/tutorials\/razor-pages\/razor-pages-start\">Razor Pages<\/a> are a page-first structure that allow you to focus on the user-interface and simplify the server-side experience by writing PageModel objects. If you are familiar with how to configure your ASP.NET Core Startup class for MVC, then you already have the following lines in your Startup class:  Surprise!\u00a0 The AddMvc and UseMvc configuration calls in your Startup class also activate the Razor Pages feature. \u00a0You can start writing a Razor Page by placing a new cshtml file called Now.cshtml in the Pages\/ top-level folder of your application.\u00a0 Let\u2019s look at a simple page that shows the current time:  This looks like a standard MVC View written in Razor, but also has the @page directive at the top to indicate that this is a stand-alone Razor Page built with that paradigm.\u00a0 <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/system.web.mvc.htmlhelper(v=vs.118).aspx\">HtmlHelpers<\/a>, <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/mvc\/views\/tag-helpers\/intro\">TagHelpers<\/a>, and other .NET Code is available to us in the course of the page.\u00a0 We can add methods just as we could in Razor views, by adding a block level element called @functions and writing methods into that element:  We can build more complex structures by taking advantage of the new PageModel object.\u00a0 The PageModel is an MVVM architectural concept that allows you to execute methods and bind properties to the Page content that is being rendered.\u00a0 We can enhance our sample by creating a NowModel.cshtml.cs C# class file in the Pages folder with this content:  With this class that inherits from PageModel, we can now do more complex interactions and build out a class that can be unit tested.\u00a0 In this case, we are simply loading the LastModified property on the Now page and setting that to the LastModified property.\u00a0 Also note the OnGet method to indicate that this PageModel handles the HTTP GET verb.\u00a0 We can update our Razor Page with the following syntax to start using the PageModel and output the last update date:  For more information, check out the <a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/mvc\/razor-pages\/\">ASP.NET Core documentation on getting started with Razor Pages.<\/a><\/p>\n<h2>Updated Templates and SPA Templates The templates that ship with ASP.NET Core have been enhanced to not only include a web application that is built with the MVC pattern, but also a razor pages web application template, and a series of templates that enable you to build single-page-applications (SPA) for the browser.\u00a0 These SPA templates use the JavaScript Services functionality to embed NodeJS within ASP.NET Core on the server, and compile the JavaScript applications server-side as part of the .NET build process. <figure id=\"attachment_10076\" aria-labelledby=\"figcaption_attachment_10076\" class=\"wp-caption aligncenter\" ><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/2-NewTemplates.png\"><img decoding=\"async\" class=\"size-large wp-image-10076\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/2-NewTemplates-1024x667-1.png\" alt=\"New ASP.NET Core Templates in Visual Studio 2017\" width=\"879\" height=\"573\" \/><\/a><figcaption id=\"figcaption_attachment_10076\" class=\"wp-caption-text\">Figure 2 &#8211; New ASP.NET Core Templates in Visual Studio 2017<\/figcaption><\/figure> These same templates are also available out of the box at the command-line when you type dotnet new: <figure id=\"attachment_10085\" aria-labelledby=\"figcaption_attachment_10085\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"wp-image-10085 size-large\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/3-CommandLineTemplates-1024x564-1.png\" alt=\"\" width=\"879\" height=\"484\" \/><figcaption id=\"figcaption_attachment_10085\" class=\"wp-caption-text\">Figure 3 &#8211; Templates available with the dotnet new command<\/figcaption><\/figure><\/p>\n<h2>DbContext Pooling with Entity Framework Core 2.0 Many ASP.NET Core applications can now obtain a performance boost by configuring the service registration of their\u00a0DbContext\u00a0types to use a pool of pre-created instances, avoiding the cost of creating new instance for every request.\u00a0 Try adding the following code to your Startup\/ConfigureServices to enable DbContext pooling:<\/h2>\n<p> You can read more information about the updates included in <a href=\"https:\/\/aka.ms\/efcore2announce\">Entity Framework Core 2.0<\/a> online in their announcement post.<\/p>\n<h2>Monitor and Profile with No Code Changes and Application Insights ASP.NET Core 2.0 runs with no modifications necessary on Azure App Service and comes with integrations that provide performance profiling, error reporting, and diagnostics from Azure Application Insights. In Visual Studio 2017, right-click on your project and choose \u201cAdd &#8211; Application Insights Telemetry\u201d to start collecting data from your application. You can then review the performance of your application including all log messages directly within Visual Studio 2017. <figure id=\"attachment_10086\" aria-labelledby=\"figcaption_attachment_10086\" class=\"wp-caption aligncenter\" ><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/4-VisualStudioTelemetry.png\"><img decoding=\"async\" class=\"size-large wp-image-10086\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/4-VisualStudioTelemetry-1024x882-1.png\" alt=\"Telemetry Reported in Visual Studio 2017\" width=\"879\" height=\"757\" \/><\/a><figcaption id=\"figcaption_attachment_10086\" class=\"wp-caption-text\">Figure 4 &#8211; Telemetry Reported in Visual Studio 2017<\/figcaption><\/figure> That\u2019s nice when you\u2019re developing your application, but what if your application is already in Azure?\u00a0 We\u2019ve got support in the Azure portal to start profiling and debugging, and it starts when you first publish your application and navigate to the cloud portal for your new app service.\u00a0 Azure will prompt you with a new purple banner indicating that Application Insights for monitoring and profiling is available <figure id=\"attachment_10095\" aria-labelledby=\"figcaption_attachment_10095\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"size-full wp-image-10095\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/5-AzureBanner-1.png\" alt=\"Banner in Azure Portal offering to assist in configuring Application Insights\" width=\"672\" height=\"80\" \/><figcaption id=\"figcaption_attachment_10095\" class=\"wp-caption-text\">Figure 5 &#8211; Banner in Azure Portal offering to assist in configuring Application Insights<\/figcaption><\/figure> When you click through that banner, you will create an Application Insights service for your application and attach those features without recompiling or redeploying.\u00a0 Shortly afterwards, your new Application Insights service will start reporting data about the activity captured. <figure id=\"attachment_10105\" aria-labelledby=\"figcaption_attachment_10105\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"size-full wp-image-10105\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/6-AzureTelemetryRequests-1.png\" alt=\"Initial Application Insights Overview on Azure Portal\" width=\"543\" height=\"735\" \/><figcaption id=\"figcaption_attachment_10105\" class=\"wp-caption-text\">Figure 6 &#8211; Initial Application Insights Overview on Azure Portal<\/figcaption><\/figure> It even shows the number of failed requests and errors in the application.\u00a0 If you click through that area, you\u2019ll see details about the failed requests: <figure id=\"attachment_10115\" aria-labelledby=\"figcaption_attachment_10115\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"size-full wp-image-10115\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/7-AzureFailedRequests-1.png\" alt=\"Failed Requests Report on Azure Portal\" width=\"566\" height=\"817\" \/><figcaption id=\"figcaption_attachment_10115\" class=\"wp-caption-text\">Figure 7 &#8211; Failed Requests Report on Azure Portal<\/figcaption><\/figure> There is a System.Exception thrown, and identified at the bottom of the screen, if we click through that reported exception, we can see more about each time that exception was thrown.\u00a0 When you click through a single instance of those exceptions, you get some neat information about the exception including the call stack: <figure id=\"attachment_10116\" aria-labelledby=\"figcaption_attachment_10116\" class=\"wp-caption aligncenter\" ><img decoding=\"async\" class=\"size-full wp-image-10116\" src=\"https:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/8-AzureExceptionAnalysis-1.png\" alt=\"Exception Analysis in the Azure Portal\" width=\"584\" height=\"762\" \/><figcaption id=\"figcaption_attachment_10116\" class=\"wp-caption-text\">Figure 8 &#8211; Exception Analysis in the Azure Portal<\/figcaption><\/figure> Snapshot debugging in Application Insights now supports ASP.NET Core 2.0.\u00a0 If you <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/application-insights\/app-insights-snapshot-debugger\">configure snapshot debugging in your application<\/a>, then the \u201cOpen Debug Snapshot\u201d link at the top will appear and show the complete call stack and you can click through method calls in the stack to review the local variables:<\/p>\n<table style=\"margin: 0px auto\">\n<tbody>\n<tr>\n<td width=\"50%\">\n        <figure id=\"attachment_10125\" aria-labelledby=\"figcaption_attachment_10125\" class=\"wp-caption aligncenter\" ><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/9-AzureStackTrace.png\"><img class=\"wp-image-10125 size-mediumlarge\" alt=\"Stack Trace in Azure Portal\" width=\"422\" height=\"350\" \/><\/a><figcaption id=\"figcaption_attachment_10125\" class=\"wp-caption-text\">Figure 9 &#8211; Stack Trace in Azure Portal<\/figcaption><\/figure>\n      <\/td>\n<td width=\"50%\">\n        <figure id=\"attachment_10126\" aria-labelledby=\"figcaption_attachment_10126\" class=\"wp-caption aligncenter\" ><a href=\"http:\/\/devblogs.microsoft.com\/aspnet\/wp-content\/uploads\/sites\/16\/2017\/08\/10-AzureLocals.png\"><img class=\"wp-image-10126 size-mediumlarge\" alt=\"Local values reported in Azure Portal\" width=\"467\" height=\"350\" \/><\/a><figcaption id=\"figcaption_attachment_10126\" class=\"wp-caption-text\">Figure 10 &#8211; Local values reported in Azure Portal<\/figcaption><\/figure>\n      <\/td>\n<\/tr>\n<\/tbody>\n<\/table>\n<p>\u00a0 Nice!\u00a0 We can go one step further and click that \u201cDownload Snapshot\u201d button in the top corner to start a debug session in Visual Studio right at the point this exception was thrown. What about the performance of these pages?\u00a0 From the Application Insights blade, you can choose the Performance option on the left and dig deeper into the performance of each request to your application. <figure id=\"attachment_10136\" aria-labelledby=\"figcaption_attachment_10136\" class=\"wp-caption aligncenter\" ><img class=\"size-mediumlarge wp-image-10136\" alt=\"Application Profiling in Azure Portal\" width=\"500\" height=\"263\" \/><figcaption id=\"figcaption_attachment_10136\" class=\"wp-caption-text\">Figure 11 &#8211; Application Profiling in Azure Portal<\/figcaption><\/figure> There are more details available in our docs about <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/application-insights\/app-insights-profiler\">performance profiling using Application Insights<\/a>. If you want the raw logs about your application, you can enable the Diagnostic Logs in App Service and set the diagnostic level to Warning or Error to see this exception get thrown. <figure id=\"attachment_10145\" aria-labelledby=\"figcaption_attachment_10145\" class=\"wp-caption aligncenter\" ><img class=\"size-mediumlarge wp-image-10145\" alt=\"Configure Logging within the Azure Portal\" width=\"500\" height=\"330\" \/><figcaption id=\"figcaption_attachment_10145\" class=\"wp-caption-text\">Figure 12 &#8211; Configure Logging within the Azure Portal<\/figcaption><\/figure> Finally, choose the Log Stream on the left and you can watch the same console that you would have on your developer workstation. \u00a0The errors and log messages of the selected severity level or greater will appear as they are triggered in Azure. <figure id=\"attachment_10155\" aria-labelledby=\"figcaption_attachment_10155\" class=\"wp-caption aligncenter\" ><img class=\"size-mediumlarge wp-image-10155\" alt=\"Live Console Logging inside the Azure Portal\" width=\"492\" height=\"350\" \/><figcaption id=\"figcaption_attachment_10155\" class=\"wp-caption-text\">Figure 13 &#8211; Live Console Logging inside the Azure Portal<\/figcaption><\/figure> All of the Application Insights features can be activated in ASP.NET Core without rebuilding and deploying.\u00a0 Snapshot debugging <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/application-insights\/app-insights-snapshot-debugger\">requires an extra step and some code to be added<\/a>, and the configuration is as simple as an extra NuGet package and a line in your Startup class. You can learn more about <a href=\"https:\/\/docs.microsoft.com\/en-us\/azure\/application-insights\/app-insights-asp-net-core\">Application Insights Telemetry in our online documentation<\/a>.<\/p>\n<h2>Razor Support for C# 7.1 The Razor engine has been updated to work with the new Roslyn compiler and that includes support for C# 7.1 features like<\/h2>\n<p><a href=\"https:\/\/github.com\/dotnet\/csharplang\">Default Expressions<\/a>, <a href=\"https:\/\/github.com\/dotnet\/csharplang\/blob\/master\/proposals\/csharp-7.1\/infer-tuple-names.md\">Inferred Tuple Names<\/a>, and <a href=\"https:\/\/github.com\/dotnet\/csharplang\">Pattern-Matching with Generics<\/a>.\u00a0 To use C #7.1 features in your project add the following property in your project file and then reload the solution:<\/p>\n<pre>&lt;LangVersion&gt;latest&lt;\/LangVersion&gt;<\/pre>\n<p>C# 7.1 is itself in a preview state, and you can review the language specification for<\/p>\n<p><a href=\"https:\/\/github.com\/dotnet\/roslyn\/blob\/master\/docs\/Language%20Feature%20Status.md\">these features on their GitHub repository<\/a>.<\/p>\n<h2>Simplified Application Host Configuration Host configuration has been dramatically simplified, with a new WebHost.CreateDefaultBuilder included in the default ASP.NET Core templates that automatically allocates a Kestrel server that will attempt to run on IIS if it is available, and configures the standard console logging providers.\u00a0 Your Program.cs file is simplified to only this content:<\/h2>\n<p> That reduces the possibility of accidentally breaking some of the standard configuration that most developers were not altering in their ASP.NET Core applications.\u00a0 Why make you write the same boilerplate code over and over, when it could be simplified to 3 lines of code?<\/p>\n<h2>Summary These updates in ASP.NET Core 2.0 provide new ways to write your applications and simplify some of the operational process of managing a production application.\u00a0 A word of thanks to our .NET Community for their feedback, issues, and contributed source code on GitHub.\u00a0 They\u2019ve really been a huge help in delivering this new version of ASP.NET Core. We encourage you to download the latest .NET Core SDK from<\/h2>\n<p><a href=\"https:\/\/dot.net\/core\">https:\/\/dot.net\/core<\/a> and start working with this new version of ASP.NET Core.\u00a0 You can watch the launch video for .NET Core 2.0 and ASP.NET Core 2.0 at: <a href=\"https:\/\/aka.ms\/dotnetcore2launchvideo\">https:\/\/aka.ms\/dotnetcore2launchvideo<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>The ASP.NET team is proud to announce general availability of ASP.NET Core 2.0.\u00a0 This release features compatibility with .NET Core 2.0, tooling support in Visual Studio 2017 version 15.3, and the new Razor Pages user-interface design paradigm.\u00a0 For a full list of updates, you can read the release notes and you can check the list [&hellip;]<\/p>\n","protected":false},"author":405,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[197,7509,327,646],"tags":[30,7265],"class_list":["post-10016","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-aspnet","category-aspnetcore","category-azure","category-visual-studio","tag-announcement","tag-announcements"],"acf":[],"blog_post_summary":"<p>The ASP.NET team is proud to announce general availability of ASP.NET Core 2.0.\u00a0 This release features compatibility with .NET Core 2.0, tooling support in Visual Studio 2017 version 15.3, and the new Razor Pages user-interface design paradigm.\u00a0 For a full list of updates, you can read the release notes and you can check the list [&hellip;]<\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/10016","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/405"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=10016"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/10016\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=10016"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=10016"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=10016"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}