BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News ASP.NET Core 2 Gains Razor Pages

ASP.NET Core 2 Gains Razor Pages

Leia em Português

This item in japanese

Bookmarks

Joining the release of .NET Core 2 and Entity Framework Core 2.0 is the third piece of the triad: ASP.NET Core 2.0.  This release provides several new features and improvements including general performance enhancements, Razor Pages, new development templates, and better support for Azure Diagnostics.

 

Let's take a look at Razor Pages first.  Razor pages resemble a standard MVC View, but use the @Page directive to indicate it is a Razor Page.  Microsoft now considers Razor Pages the recommended way to build UI for web applications in ASP.NET Core, but developers are of course free to choose the approach that works best for them.  Using Razor Pages allows web pages to be written that handle requests directly without going through a controller (as would be the case in a standard ASP.NET MVC application).

 

Another benefit of moving to ASP.NET Core 2 is the ability to take advantage of simplified package references.  Your project’s .csproj file need only reference Microsoft.AspNetCore.All which is a metapackage that ensures all of the libraries needed by your application are available without complicating the matter.  Publishing a web app will cause only the libraries your project needs to be distributed with your application, which avoids file bloat.  Another advantage to using the metapackage is that it enables faster application startup time through its use of the .NET Core Runtime Store, which precompiles all of the packages and files within it.  As this meta-package is intended as a conveince, it does not prevent developers from continuing to reference specific packages in Microsoft.AspNetCore.* directly.

 

To support the new features, the ASP.NET Core 2 templates have been expanded to include templates for Razor Pages (titled Web Application), Web API, MVC-based web applications, Angular, React.js and React.js & Redux.  All of these are also available via the command line and do not depend on Visual Studio 2017.

 

The Razor language engine supports the features of C# 7.1 when explicitly enabled.  To take advantage of these features, add this property to your project file: 

<LangVersion>latest</LangVersion>

Afterwards, reload the solution for your changes to take effect.


Those planning to deploy their applications to Azure will notice that applications built for ASP.NET Core 2 require no modification to take advantage of Azure App Service.  This can be performed within VS2017 or directly from within the Azure portal.  

 

Developers with existing ASP.NET Core 1.X packages can consult Microsoft’s upgrade guide for migration details in upgrading their application to ASP.NET Core 2.0.  To use ASP.NET 2.0 download the .NET Core 2 SDK, which is available independently of VS2017.

Rate this Article

Adoption
Style

BT