Original: Announcing. NET Core 2.1
We are happy to be able to publish. NET Core 2.1. This update includes improvements to performance, improvements to runtimes and tools. It also includes a new way to deploy tools in the form of NuGet packages. We have added aSpan<T>new primitive type called, which can manipulate data without memory allocations. There are many other new APIs that focus on cryptography, compression, and Windows compatibility. It is the first version that supports Alpine Linux and ARM32 chips. You can start updating your existing project to. NET Core 2.1 today. This version is compatible with. NET Core 2.0, and the update becomes simple.
ASP. NET core 2.1 and Entity Framework Core 2.1 have also been released today.
You can download and start using. NET Core 2.1 on Windows,macos and Linux:
- . NET Core 2.1 SDK (includes the runtime)
- . NET Core 2.1 Runtime
Docker images for. NET core and ASP. are also available: microsoft/dotnet
The Build 2018 conference was held earlier this month. We have a few in-depth demos of. NET Core. You can view Build 2018 sessions for. NET on Channel9.
You can see the full details of the release in the. NET Core 2.1 Release notes. The release notes contain instructions, known issues, and workarounds. Please submit any questions you find in the comments or in the Dotnet/core #1614
Thanks to everyone who contributed to. NET Core 2.1. You've helped. NET Core become a better product!
Long-term support long-term
. NET Core 2.1 will be a long-term support (LTS) version. This means that it will support three years. We recommend that you use. NET Core 2.1 as the new standard for. NET core development.
We intend to release a few important updates within the next 2-3 months, and then formally publish. NET Core 2.1 as LTS. Later, the update will be for security, reliability, and add platform support (e.g. Ubuntu 18.10). We recommend that you start with. NET Core 2.1 now. For applications that are in an active development state, there is no reason to defer the deployment of. NET Core 2.1 into a production environment. For applications that are not actively developing, we recommend that you wait for deployment until you declare. NET Core 2.1 as LTS.
There are several reasons to upgrade to. NET Core 2.1:
- Long-term support (LTS).
- Superior performance and quality.
- New platform support, for example: Ubuntu 18.04,alpine,arm32.
- Easier to manage platform dependencies and self-contained application publishing in project files.
We have received many requests to have. NET Core 2.0 as the LTS version. In fact, that was our original plan. We chose to wait until we solved the challenges of managing platform dependencies (last one o'clock above). Platform-dependent management is an important issue in. NET Core 1.0 and gradually improves with each release. For example, you will notice that the ASP. NET Core Package Reference no longer contains the version number of.
Platform Support Platform
. NET Core 2.1 supports the following operating systems:
- Windows Client:7, 8.1, 10 (1607+)
- Windows server:2008 R2 sp1+
- macos:10.12+
- rhel:6+
- fedora:26+
- ubuntu:14.04+
- debian:8+
- sles:12+
- opensuse:42.3+
- alpine:3.7+
Chip support is as follows:
- Windows,macos and Linux on the x64
- x86 on Windows
- ARM32 on Linux (Ubuntu 18.04+,debian +)
Note: Raspberry Pi is supported. NET Core 2.1. It is not supported on Pi Zero or other devices that use the ARMV6 chip.. NET Core requires a ARMv7 or ARMV8 chip, such as ARM cortex-a53.
. NET Core Tools Tools
. NET Core Tools now has a new deployment and extension mechanism. This new experience is very similar to the NPM Global tool and is inspired by NPM. You can create your own global tools by looking at the Dotnetsay tools sample.
You can use the following command to try Dotnetsay:
dotnet tool install -g dotnetsaydotnetsay
. NET core tools is a. NET Core console application that is packaged and acquired as a NuGet package. By default, these tools are framework-dependent applications and contain all of their NuGet dependencies. This means that. NET core tools runs by default on all operating systems and chip architectures that support. NET core, with a set of binary files. By default, thedotnet tool installcommand looks for tools on nuget.org. You can also use your own NuGet Feed instead.
Currently,. NET Core Tools supports global installation only and requires the-G parameter. We are also undertaking various forms of local installation and are scheduled to be available in subsequent releases.
We expect a new tools ecosystem to serve itself. @natemcmaster maintains a list of dotnet tools. You can also look at his dotnet-serve tools.
The following existing Dotnetclireferencetool tools have been converted to built-in tools.
- dotnet watch
- dotnet dev-certs
- dotnet user-secrets
- dotnet sql-cache
- dotnet ef
When upgrading to. NET Core 2.1, remove project references for these tools.
Build performance improvements Building performance optimizations
Improving the performance of. NET Core builds may be the biggest focus of this release. It has been greatly improved in. NET Core 2.1, especially for incremental builds. These improvements apply to builds on the command linedotnet buildand in Visual Studio.
The improvements we've made are shown in comparison to. NET Core 2.0. We specialize in large projects, as you can see from images.
(Figure: Performance improvements in. NET Core 2.1 Incremental build.) Note: Figure 2.1 refers to the 2.1.300 SDK version. )
(Note: These test data are from the Mikeharder/dotnet-cli-perf project.) )
We add long-running servers to the. NET Core SDK to improve the performance of common development operations. These servers attach a process that runs longer than a single dotnet build call. Some of them are migrated from the. NET Framework and others are brand new.
The following SDK build servers have been added:
- Vbcscompiler
- MSBuild worker Processes
- Razor Server
The main advantage of these servers is that they skip the need to JIT-compile chunks of code in each dotnet build call. They will automatically terminate after a certain period of time. For more information about better control over these build servers, see the release notes.
Runtime performance improvements run-time performance optimization
See the article on performance improvements in. NET Core 2.1 for an in-depth look at all the performance improvements in this release.
Networking Performance Improvements Network performance optimization
We built a new httpclienthandler called Sockethttphandler to improve network performance. It is aC # implementation of HttpClient based on. NET sockets and Span.
Socketshttphandler is now the default implementation of HttpClient. Socketshttphandler's greatest triumph is performance. It is much faster than the existing implementation. It also eliminates platform-specific dependencies and supports consistent behavior across operating systems.
For instructions on how to enable the old network stack, see the. NET Core 2.1 Release notes.
Span, Memory, and friends
We are entering a new era of memory efficient computing using. NET, with the introduction of Spanand related types. Today, if you want to pass the first 1000 elements in an array of 10,000 elements, you need to copy the 1000 elements and pass the copy to the caller. This operation is expensive in both time and space. The new Spantype allows you to provide a virtual view of the array without the cost of time or space. Spanis a struct, which means that you can enable complex pipelining of analysis or other computations without assigning. For this reason, we use this new type extensively in Corefx.
Jared Parsons A good introduction to his Channel 9 video C # 7.2:understanding Span. Stephen Toub also has an article about these c#–all about span:exploring a New. NET mainstay.
In the simplest case, you can convert an array to span, as shown below.
var arr = new byte[10];Span<byte> bytes = arr; // Implicit cast from T[] to Span<T>
You can slice a Spanas shown below.
// generating data for the example
int[] ints = new int[100];
for (var i = 0; i < ints.Length; i++)
{
ints[i] = i;
}
// creating span of array
Span<int> spanInts = ints;
// slicing the span, which creates another (subset) span
Span<int> slicedInts = spanInts.Slice(start: 42, length: 2);
// printing composition of the array and two spans
Console.WriteLine($"ints length: {ints.Length}");
Console.WriteLine($"spanInts length: {spanInts.Length}");
Console.WriteLine($"slicedInts length: {slicedInts.Length}");
Console.WriteLine("slicedInts contents");
for (var i = 0; i < slicedInts.Length; i++)
{
Console.WriteLine(slicedInts[i]);
}
// performing tests to validate the span has the expected contents
if (slicedInts[0] != 42) Console.WriteLine("error");
if (slicedInts[1] != 43) Console.WriteLine("error");
slicedInts[0] = 21300;
if (slicedInts[0] != ints[42]) Console.WriteLine("error");
// printing composition of subset span
Console.WriteLine("slicedInts contents");
for (var i = 0; i < slicedInts.Length; i++)
{
Console.WriteLine(slicedInts[i]);
}
The code produces the following output:
ints length: 100
spanInts length: 100
slicedInts length: 2
slicedInts contents
42
43
slicedInts contents
21300
43
Brotli Compression Brotli Compression
Brotli is a general-purpose lossless compression algorithm that is comparable to the best general-purpose compression methods available today. The speed is similar to deflate, but provides more powerful compression. The specifications for the Brotli compressed data format are defined in RFC 7932. Most Web browsers, major Web servers, and some CDN (Content Delivery Networks) Support Brotli encoding.. NET Core Brotli Implementation based on C code provided by Google on Google/brotli 。 Thank you, Google!
Brotli support has been added to. NET Core 2.1. Operations can be done using stream-based Brotlistream or Brotliencoder/brotlidecoder classes based on high-performance spans. You can see that it is used in the following example.
using System;
using System.IO;
using System.IO.Compression;
using System.Net.Http;
using System.Threading.Tasks;
using static System.Console;
namespace BrotliApp
{
class Program
{
static readonly string s_URL = "https://raw.githubusercontent.com/dotnet/core/master/README.md";
static async Task Main(string[] args)
{
var client = new HttpClient();
var response = await client.GetAsync(s_URL,HttpCompletionOption.ResponseHeadersRead);
var stream = await response.Content.ReadAsStreamAsync();
WriteLine($"Request URL: {s_URL}");
WriteLine($"Initial content length: {response.Content.Headers.ContentLength}");
var compressedStream = CompressWithBrotli(stream);
WriteLine($"Compressed content length: {compressedStream.Length}");
var decompressedStream = DecompressWithBrotli(compressedStream);
WriteLine($"Decompressed content length: {decompressedStream.Length}");
WriteLine($"Compression ratio: {100 - (Decimal.Divide(compressedStream.Length, response.Content.Headers.ContentLength.Value)*100):N1}%");
WriteLine("First 10 lines of decompressed content");
WriteLine();
var reader = new StreamReader(decompressedStream);
for (var i = 0; i < 10; i++)
{
WriteLine(reader.ReadLine());
}
}
public static Stream CompressWithBrotli(Stream toCompress)
{
MemoryStream compressedStream = new MemoryStream();
using (BrotliStream compressionStream = new BrotliStream(compressedStream, CompressionMode.Compress, leaveOpen: true))
{
toCompress.CopyTo(compressionStream);
}
compressedStream.Position = 0;
return compressedStream;
}
public static Stream DecompressWithBrotli(Stream toDecompress)
{
MemoryStream decompressedStream = new MemoryStream();
using (BrotliStream decompressionStream = new BrotliStream(toDecompress, CompressionMode.Decompress, leaveOpen: true))
{
decompressionStream.CopyTo(decompressedStream);
}
decompressedStream.Position = 0;
return decompressedStream;
}
}
}
The code produces the following output:
Request URL: https://raw.githubusercontent.com/dotnet/core/master/README.md
Initial content length: 2244
Compressed content length: 727
Decompressed content length: 2244
Compression ratio: 67.6%
First 10 lines of decompressed content
# .NET Core Home
The dotnet/core repository is a good starting point for .NET Core.
The latest major release is [.NET Core 2.1](release-notes/2.1/2.1.0.md). The latest patch updates are listed in [.NET Core release notes](release-notes/README.md)
## Download the latest .NET Core SDK
* [.NET Core 2.1 SDK](release-notes/download-archives/2.1.0-download.md)
New Cryptography APIs
The. NET Core Cryptography API has made the following enhancements:
-
- New signedcms APIs -system.security.cryptography.pkcs.signedcms is now available in the System.Security.Cryptography.Pkcspackage. NET core implementation is available to all. NET core platforms and have par Ity with the class from the. NET Framework. See:dotnet/corefx #14197.
-
- New X509certificate.getcerthash overload for SHA-2 -new overloads for X509certificate.getcerthash and X509certi Ficate. Getcerthashstring accept a hash algorithm identifier to enable callers to get certificate thumbprint values using Algorith Ms other than SHA-1. Dotnet/corefx #16493.
-
- New Span-based Cryptography APIs -span-based APIs is available for hashing, HMAC, (Cryptogra phic) random number generation, asymmetric signature generation, asymmetric signature processing, and RSA encryption.
-
- rfc2898derivebytes Performance Improvements -the implementation of Rfc2898derivebytes (PBKDF2) is about 15% fast Er, based on using Span-based. Users who benchmarked a iteration count for a amount of server time may want to update iteration count accordingly.
-
- Added cryptographicoperations class -cryptographicoperations.fixedtimeequals takes a fixed amount of time to RET Urn for any and inputs of the same length, making it suitable for use on cryptographic verification to avoid contributing To timing side-channel information. Cryptographicoperations.zeromemory is a memory clearing routine this cannot be optimized away via a write-without-subseque Nt-read optimization.
-
- Added static Randomnumbergenerator.fill -the static Randomnumbergenerator.fill would Fill a Span with random valu Es using the system-preferred csprng, and does not require the caller to manage the lifetime of a IDisposable resource.
-
- Added support for RFCs 3161 cryptographic timestamps -new API to request, read, validate, and create Timestamptok En values as defined by RFC 3161.
-
- Add Unix envelopedcms -the EnvelopedCms class have been added for Linux and MacOS.
-
- Added Ecdiffiehellman -elliptic-curve Diffie-hellman (ECDH) is now available on. NET Core via the Ecdiffiehellma N class family with the same surface area as. NET Framework 4.7.
-
- Added Rsa-oaep-sha2 and RSA-PSS to Unix platforms -starting with. NET Core 2.1 The instance provided by RSA. Create () can always encrypt or decrypt with OAEP using a SHA-2 digest, as well as generate or validate signatures using RS A-pss
Windows compatibility Pack
When porting existing code from the. NET Framework to. NET Core, you can use Windows compatibility Pack. It provides an additional 20,000 APIs compared to the APIs available in. NET Core. This includes system.drawing,eventlog,wmi, performance counters, and Windows services. For more information, see announcing the Windows compatibility Pack for. NET Core.
The following example shows access to the Windows registry using the APIs provided by Windows compatibility Pack.
private static string GetLoggingPath()
{
// Verify the code is running on Windows.
if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
{
using (var key = Registry.CurrentUser.OpenSubKey(@"Software\Fabrikam\AssetManagement"))
{
if (key?.GetValue("LoggingDirectoryPath") is string configuredPath)
return configuredPath;
}
}
// This is either not running on Windows or no logging path was configured,
// so just use the path for non-roaming user-specific data files.
var appDataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
return Path.Combine(appDataPath, "Fabrikam", "AssetManagement", "Logging");
}
Tiered compilation layered compilation
We added a new, exciting feature preview for the runtime called Layered compilation. This is a way for the runtime to use the Just-in-time (JIT) compiler more adaptively for better performance.
The basic challenge of the JIT compiler is that compile time is part of the application execution time. Generating better code usually means spending more time optimizing it. But if a piece of code executes only once or a few times, the compiler may spend more time optimizing it instead of just running the non-optimized version.
With layered compilation, the compiler first generates code as quickly as possible, with minimal optimizations (first layer). Then, when it detects that some methods have performed a lot, it generates a more optimized version of these methods (the second tier) and then replaces them with them. The second layer of compilation is executed in parallel, eliminating the contradiction between fast compilation speed and the generation of optimal code. This model can be more generally referred to as adaptive optimization.
Layered compilation also benefits long-running applications, such as Web servers. We'll cover this in more detail in the next sections, but the short version is that JIT can generate better code than the precompiled assembly we provide for. NET Core itself. This is mainly due to the fragile binary interface problem. With layered compilation, the JIT can use the precompiled code it finds for. NET Core, and then compile better code for the method that needs to be called. We have seen that this situation has a great impact on the testing in our performance labs.
You can test for hierarchical compilation by setting environment variables:
COMPlus_TieredCompilation="1"
You can enable hierarchical compilation for your application by setting the Tieredcompilation property, as you see in this project.
Self-contained application publishing self-contained application published
Dotnet Publish now publishes self-contained applications with the service runtime version. When you publish a self-contained application using the new SDK, your application will contain the latest version of the service runtime known to the SDK. When you upgrade to the latest SDK, you will publish with the latest. NET Core runtime version. This applies to. NET Core 1.0 runtimes and later versions.
The self-contained publication relies on the runtime version on nuget.org. You don't need to have the service running on your machine.
UnlessRuntimeFrameworkVersiona different version is specified with a property, the. NET Core 2.0 SDK is used, and the self-contained application will be published with the. NET Core 2.0.0 Runtime. With this new behavior, you will no longer need to set this property to select a higher version of the runtime for self-contained applications. The simplest approach is to always install and publish using the latest SDK.
Docker
The microsoft/dotnet on the Docker hub provides a docker image for. NET Core 2.1. We have made some changes relative to. NET Core 2.0. We have integrated the Docker Hub repository collection for. NET core and ASP. We will use microsoft/dotnet as our only repository for. NET Core 2.1 and later releases.
We added a set of environment variables to the. NET core image to host the ASP. NET core site and enable it in the SDK container imagedotnet watchwithout additional configuration.
The. NET Core Docker Sample has been moved to the Dotnet/dotnet-docker library. These examples have been updated for. NET Core 2.1. New samples have been added, including hosting an ASP. NET Core Docker image over HTTPS.
For more information, see. NET Core 2.1 Docker image updates.
. NET Core 2.1 and compatibility
. NET Core 2.1 is a highly compatible version. In cases where. NET Core 2.0 is not installed, the. NET Core 2.0 application will run on. NET Core 2.1. This roll-forward behavior applies only to minor versions, and. NET Core 1.1 does not roll forward to 2.0,.net Core 2.0 and does not roll forward to 3.0.
For instructions on how to disable minor versions roll forward, see the. NET Core 2.1 Release notes.
If you are using. NET Core 2.1 preview to build a. NET Core 2.1 application or tool, you must rebuild with the final. NET Core 2.1 version. The preview version does not roll forward to the final version.
Early snap Installer Support early Snap installer supports
We've been working to bring. NET Core into Snap and ready to listen to your ideas. Snaps, among other technologies, is an emerging application installation and sandbox technology that we consider very interesting. Snap installation is for Debian-based systems and other distributions, such as Fedora, which is facing the challenge we are trying to solve. If you want to try it, you can use the following steps.
The. NET Core 2.1 Runtime and the SDK Snap are available:
- sudo snap install dotnet-sdk --candidate --classic
- sudo snap install dotnet-runtime-21 --candidate
Pay attention to future articles and explore the contents of Snaps. At the same time, we are happy to listen to your feedback.
Closing Epilogue
. NET Core 2.1 is a big step forward for the platform. We've dramatically improved performance, added many APIs, and added new ways to deploy tools. We have also added support for new Linux distributions and another type of CPU ARM32. This release expands the place where you can use. NET Core and makes it more efficient everywhere.
We expect. NET Core 2.1 to be available in Azure App Service later in the week.
You can see the progress we have made with the. NET Core 2.1 Temporary release: Rc1,preview 2,preview 1. Thanks again for all the people who contributed to this release.
[Translate]. NET Core 2.1 Release