ASP.NET 5 beta7 is now available both on NuGet and as a tooling update to Visual Studio 2015! This release also includes the first public preview of the .NET Execution Environment (DNX) for Mac and Linux based on .NET Core – no Mono required. Let’s take a look at how we can get started with ASP.NET 5 beta7.
Note: To use ASP.NET 5 beta7 with Visual Studio 2015, you will need to download and install the beta7 version (14.0.60831.0) of ASP.NET and Web Tools 2015.
On Windows download and install the latest ASP.NET and Web Tools updates for Visual Studio 2015.
Getting started with the new .NET Execution Environment (DNX) for .NET Core on Mac/Linux
The .NET Execution Environment (DNX) provides a consistent way to build and run cross-platform .NET projects and is the basis for ASP.NET 5. In previous preview releases we provided DNXs for the full .NET Framework, Mono and .NET Core. The .NET Core support was initially limited to Windows, but in this release DNX support for .NET Core is now available in a limited fashion for both Mac and Linux. You can find instructions for installing DNX for .NET Core on Mac and Linux in our documentation.
What else is new?
In addition to the new support in DNX for cross-platform .NET Core this release is loaded with new features and improvements. For a full list of what is new in this release please refer to the beta7 release notes. Below is summary of some of the highlights:
.NET Execution Environment (DNX)
Drop the dot. Use `dnx web` instead of `dnx . web`
DNX now by default looks in the current folder for a project to run. Instead of `dnx . web` just type `dnx web`. To explicitly specify the path to the DNX project to run you can use the –project option.
Improved `dnu restore` output
You can now easily see which package sources were used after doing a `dnu restore`. You can even see which NuGet.Config files were used to determine the set of package sources used:
Better handling of for incompatible package dependencies
You now get useful errors when trying to consume packages from a DNX based project that do not support the frameworks targeted by the project:
Specify which .NET Framework version to run
When running on the full .NET Framework you can now use the new –framework switch with DNX to specify which .NET Framework version to use (ex. dnx451, dnx452, dnx46).
Support for app.config when running on the full .NET Framework
When running on the full .NET Framework you can now use System.Configuration to access configuration data in app.config from a DNX based console application. Simply put your XML configuration file next to your project.json file.
Specify the OS when installing DNX using DNVM
You can now use the -os flag to specify the OS when installing a DNX using DNVM. For example, you can install a DNX for Linux on Windows and then publish an app with a Linux runtime from a Windows machine.
More details from `dnvm list`
The new -detailed flag to `dnvm list` now shows the location for each installed DNX.
New unit testing templates
You can now quickly get started with unit testing for DNX based projects using the new xUnit Test Project from SideWaffle. You can also generate a unit testing project from the command-line using the Yeoman ASP.NET generators. Check out Sayed Hashimi’s blog post on Unit testing with DNX (ASP.NET 5) projects for all the details.
Support for discovering async tests
Previously you could only write and discover synchronous unit tests for DNX projects. You can now write and discover asynchronous tests.
Kestrel now supports writing chunked responses automatically when no content length is specified for the response.
Write behind buffering
Kestrel now uses write-behind buffering to more efficiently write responses to the network.
Razor comment blocks no longer introduce unnecessary whitespace
In previous versions a Razor comment block would leave unnecessary white space in your rendered views. Razor is now smart about removing this whitespace when the entire line consists of a Razor block. Your rendered views now look cleaner and consume less bandwidth.
The new ViewComponentResult in MVC makes it easy to return the result of a ViewComponent from an action. This allows you to easily expose the logic of a ViewComponent as a standalone endpoint.
In previous releases of MVC handling of URLs containing a ~ to refer to the web root of the application was handled directly in Razor. Any instances of ~ in your views were handled this way even if the value wasn’t a URI.
Support for ~ is now moved out of Razor into the new UrlResolutionTagHelper, which restricts handling of ~ to only src and href attributes of well-known HTML elements. The UrlResolutionTagHelper is added by default, but can be removed using the @removeTagHelper directive. Hurrah for
Restrict child elements using RestrictChildrenAttribute
Sometime you have multiple tag helpers that work in conjunction with each other where one tag helper is the parent of another (ex. rows/columns in a grid). You can now declare that a tag helper expects only certain child elements using the RestrictChildrenAttribute. The parser will throw an error if other elements are found and this metadata can be used by tooling to provide a better editing experience (ex. red squiggles for invalid child elements).
Support for elements without end tags
You can now use the TagStructure.WithoutEndTag option in the TargetElementAttribute to specify that a tag helper should apply to an element even when it has no end tag (includes self-closing tags). You can detect the form of the element using the updated TagMode property on TagHelperOutput.
Re-execute child content
You can now use tag helpers to have template-like behavior by re-executing child content using TagHelperContext.GetChildContentAsync(useCachedResult: false).
For example, you can now write a custom RepeaterTagHelper like this:
And when you use it in a view like this:
You get rendered output like this:
Support for conditional attributes
You can now use conditional attributes with tag helpers. Unbound tag helper attributes that evaluate to null or false are automatically removed.
Refactor class name on file name change
You now have the option in DNX based projects to refactor the class name when the file name for the class is changed.
Package search (CTRL+.) now limits suggestions to framework assemblies
From within Visual Studio 2015 you can use CTRL+. to find and install packages for APIs that you want to use. Previously the set of packages searched included all packages previously installed. This behavior has been refined to include only core framework packages.
Debug logger included in ASP.NET 5 project templates
The ASP.NET 5 project templates in Visual Studio now include the Debug logger by default so you can conveniently see logged messages in the Output window.
New project template folder structure
Based on community feedback we’ve updated the folder structure of the ASP.NET 5 project templates to provide clean separation between data models and view models.
Tag helper tool tips
You now get tool tips for tag helpers in the HTML editor. You can see which type implements the tag helper:
And also the properties for each bound attribute:
For tag helpers that have triple slash comments and have been built as a package you can also see the descriptions from the comments:
This release of ASP.NET 5 includes the first preview release of the .NET Execution Environment (DNX) for .NET Core on Mac and Linux. In addition, this release includes a variety of new runtime features and tooling enhancements. We hope you enjoy trying out ASP.NET 5 beta7! Please download and try out ASP.NET 5 beta7 today and let us know what you think on GitHub.