{"id":3196,"date":"2020-03-06T10:57:40","date_gmt":"2020-03-06T03:57:40","guid":{"rendered":"http:\/\/vietnam.briswell.com\/?p=3196"},"modified":"2020-08-27T21:15:56","modified_gmt":"2020-08-27T14:15:56","slug":"net-core-3-new-features","status":"publish","type":"post","link":"https:\/\/www.briswell-vn.com\/en\/news\/net-core-3-new-features\/","title":{"rendered":".NET Core 3 Introduce new features"},"content":{"rendered":"<p>.Net Core is a free and open-source cross-platform software framework for Windows, Linux and macOS. .NET Core 3.0 was announced on May 7, 2019 and was officially released on September 23, 2019 and the later version .NET Core 3.1 was released just a few months later, on December 3, 2019. The .Net Core team has made many improvements and new features in this version.\u00a0Let\u2019s find out what these new features are in this article.\u00a0<span title=\"\">However, in the scope of this article, we only introduce some outstanding features such as programming with Windows Forms, WPF in .NET Core, Blazor framework, new features of C # 8. If you want to learn fully<\/span><span class=\"\" title=\"\">\u00a0about .NET Core 3.0 and .NET Core 3.1, refer to the link provided at the end of the article.<\/span><\/p>\n<h1><strong>Supported platforms<\/strong><\/h1>\n<p>All the supported operating systems are listed below (based on what was announced officially from Microsoft):<\/p>\n<ul>\n<li>Alpine: 3.9+<\/li>\n<li>Debian: 9+<\/li>\n<li>openSUSE: 42.3+<\/li>\n<li>Fedora: 26+<\/li>\n<li>Ubuntu: 16.04+<\/li>\n<li>RHEL: 6+<\/li>\n<li>SLES: 12+<\/li>\n<li>macOS: 10.13+<\/li>\n<li>Windows Client: 7, 8.1, 10 (1607+)<\/li>\n<li>Windows Server: 2012 R2 SP1+<\/li>\n<\/ul>\n<h1><strong>Download<\/strong><\/h1>\n<p>You can get started using .Net Core by downloading it. Or if you already experienced with .NET Core before, you can install new version by using the following link.<\/p>\n<p><a href=\"https:\/\/dotnet.microsoft.com\/download\/dotnet-core\">https:\/\/dotnet.microsoft.com\/download\/dotnet-core<\/a><\/p>\n<h1><strong>Integrated Development Environment<\/strong><\/h1>\n<p>With new C# 8.0 included, it\u2019s highly recommended that you use Visual Studio 2019 version 16.3\u00a0\u00a0or newer, Visual Studio for Mac 8.3\u00a0or newer, or Visual Studio Code to create your applications in .Net Core 3.0.<\/p>\n<h1><strong>Porting from .NET framework and .NET Core 2<\/strong><\/h1>\n<p>If you came from .NET framework, the following article may be helpful for you to port from .NET framework to .net core generally by providing the overview of the porting process and a list of useful tools.<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/porting\/\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/porting\/<\/a><\/p>\n<p>If you want to migrate from .NET Core 2 to .NET Core 3, some of the obsolete features that may affect your applications are listed below.<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/compatibility\/2.2-3.0\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/compatibility\/2.2-3.0<\/a><\/p>\n<h1><strong>What\u2019s new in .NET Core 3?<\/strong><\/h1>\n<h3><strong>Windows forms and Windows Presentation Foundation (WPF)<\/strong>:<\/h3>\n<p>.NET Core 3 brings support for Windows Desktop apps built with WPF and Windows Forms. But for now, this feature is only supported on Windows. Although the .NET Core Runtime is cross-platform, but with the desktop frameworks, your desktop applications still reply on underlying Windows platform.<\/p>\n<p>You can migrate your Windows Forms and WPF applications using .NET Core. Or you can create new applications with just a few simple commands (.NET Core CLI). After migrating, your applications can get so many benefits from .Net Core 3 such as framework deployments (self-contained or side-by-side), better runtime performance for certain classes of APIS (such as I\/O and networking), new language features in C# 8, and Windows 10 capabilities (MSIX packaging technology, platform APIS via NuGET, and UI updates with XAML Islands.)<\/p>\n<pre><span style=\"color: #333399\">dotnet new wpf\r\ndotnet new winforms<\/span><\/pre>\n<p>Visual Studio 2019 adds\u00a0<strong>New Project<\/strong>\u00a0templates for .NET Core 3 Windows Forms and WPF.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3491 size-full\" src=\"https:\/\/briswell-vn.com\/wp-content\/uploads\/2020\/03\/2020-02-24_112235-1.png\" alt=\"\" width=\"1024\" height=\"680\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092711\/2020-02-24_112235-1.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092711\/2020-02-24_112235-1-300x199.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092711\/2020-02-24_112235-1-768x510.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<h3><strong>Blazor:<\/strong><\/h3>\n<p>Blazor is a framework in ASP.NET Core for building interactive client-side web UI. Blazor apps consist of composable UI components implemented using Razor syntax (HTML, CSS, and C#). Blazor framework comes with two models: 1) server-side hosting model and 2) client-side hosting model.<\/p>\n<p>In the server-side hosting model, Blazor is executed on the server from within an ASP.NET Core app.<\/p>\n<p>In the client-side model, the Blazor app, its dependencies, and the .NET runtime are downloaded to the browser, and the app is executed directly on the browser.\u00a0The coolest thing is that you do not need to install any add-on on the browser for the application to run.\u00a0The Blazor app can run on the browser without the need of Javascript.<\/p>\n<p>To create new app, choose &#8216;Blazor App&#8217; template as below:<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3492 size-full\" src=\"https:\/\/briswell-vn.com\/wp-content\/uploads\/2020\/03\/2020-02-24_112400-1.png\" alt=\"\" width=\"1024\" height=\"680\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092827\/2020-02-24_112400-1.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092827\/2020-02-24_112400-1-300x199.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092827\/2020-02-24_112400-1-768x510.png 768w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/p>\n<h3><strong>Compile\/deploy:<\/strong><\/h3>\n<p>According to Microsoft, .NET Core now builds executables by default. This is new in .NET Core 3. When using \u2018<em>dotnet build<\/em>\u2019 or \u2018<em>dotnet publish<\/em>\u2019, you can generate executable file matching the current environment or using command \u2018<em>dotnet publish -r &lt;RID&gt; &#8211;self-contained false<\/em>\u2019 to generate executable file matching a specific environment. To run the app, you can double-click on the file or launch it by from the command prompt directly.<\/p>\n<p>Single-file executable is also a cool feature in .NET Core 3. Now you can easily build a single EXE file that contains the entire application. You do not need a specific framework installed as well. Now developers can build their app under one EXE file and anyone can use that file to run it on their own machines. All the redundant .dll files or any other assemblies are not seen anymore.<\/p>\n<p><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-3493 size-large\" src=\"https:\/\/briswell-vn.com\/wp-content\/uploads\/2020\/03\/2020-02-24_112122-1024x546.png\" alt=\"\" width=\"1024\" height=\"546\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092952\/2020-02-24_112122-1024x546.png 1024w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092952\/2020-02-24_112122-300x160.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092952\/2020-02-24_112122-768x409.png 768w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04092952\/2020-02-24_112122.png 1366w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/> <img loading=\"lazy\" decoding=\"async\" class=\"alignnone size-medium wp-image-3494\" src=\"https:\/\/briswell-vn.com\/wp-content\/uploads\/2020\/03\/2020-02-24_112158-300x273.png\" alt=\"\" width=\"300\" height=\"273\" srcset=\"https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04093026\/2020-02-24_112158-300x273.png 300w, https:\/\/s3-ap-southeast-1.amazonaws.com\/homepage-media\/wp-content\/uploads\/2020\/03\/04093026\/2020-02-24_112158.png 550w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Many more interesting features:<\/strong><\/p>\n<ul>\n<li>High performance JSON APIs<\/li>\n<li>The garbage collector uses less memory<\/li>\n<li>.NET Standard 2.1<\/li>\n<li>Linux improvements<\/li>\n<li>Security improvements<\/li>\n<li>Update new SingalR code<\/li>\n<li>More<\/li>\n<\/ul>\n<h1><strong>What\u2019s new in C# 8?<\/strong><\/h1>\n<p>Many new patterns are introduced in C# 8. Below are some of the outstanding one you should consider to use in your applications to enhance the performance and code optimization.<\/p>\n<h3><strong>Ranges, indexes:<\/strong><\/h3>\n<p><strong>Index<\/strong>\u00a0is a new type that describes an array index (starting from 0). Especially, with the prefix ^, the index counts from the end. Examples for both cases are below.<\/p>\n<pre><span style=\"color: #333399\">Index<\/span> <span style=\"color: #800080\">i1<\/span> = 0; \r\n<span style=\"color: #333399\">Index<\/span> <span style=\"color: #800080\">i2<\/span> = ^1; \r\n<span style=\"color: #333399\">int<\/span>[] a = { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; \r\n\/\/ a[<span style=\"color: #800080\">i1<\/span>] = 0, <span style=\"color: #800080\">a[i2]<\/span> = 9;<\/pre>\n<p>With two Index values, we can create Range\u00a0is a new type<\/p>\n<pre><span style=\"color: #333399\">var<\/span> arr1 = [1..4];\r\n<span style=\"color: #333399\">var<\/span> arr2 = [^<span class=\"hljs-number\">2.<\/span>.^<span class=\"hljs-number\">0<\/span>];<\/pre>\n<h3><strong>Nullable reference types<\/strong><\/h3>\n<p>When this feature is enabled, the compiler enforces null-checking at compile time to make sure that you\u2019ve correctly checked all the null references. To enable this feature in your project, adjust the following property:<\/p>\n<pre>&lt;<span style=\"color: #333399\">PropertyGroup<\/span>&gt;\r\n  &lt;<span style=\"color: #333399\">Nullable<\/span>&gt;enable&lt;\/<span style=\"color: #333399\">Nullable<\/span>&gt;\r\n&lt;\/<span style=\"color: #333399\">PropertyGroup<\/span>&gt;\r\n\r\n<\/pre>\n<pre><span style=\"color: #333399\">string<\/span>? str = null;\r\n<span style=\"color: #333399\">Console<\/span>.<span style=\"color: #333399\">Writeline<\/span>($\u201dstr[<span style=\"color: #800080\">0<\/span>]\u201d); \/\/ you will get the warning because str may be null\r\n\r\n<\/pre>\n<pre><span style=\"color: #333399\">string<\/span>? str = null;\r\n<span style=\"color: #333399\">if<\/span> (str != null) {\r\n   <span style=\"color: #333399\">Console<\/span>.<span style=\"color: #333399\">Writeline<\/span>(<span style=\"color: #333399\">$<\/span>\u201dstr[<span style=\"color: #800080\">0<\/span>]\u201d); \/\/ the checking will remove the warning\r\n}<\/pre>\n<h3><strong>Async streams:<\/strong><\/h3>\n<p>This feature allows you to <strong>await<\/strong> upon <strong>foreach<\/strong>. Look at the example below, getQueriesAsync must be a method that is declared with async modifier and return an IAsyncEnumerable&lt;T&gt;. This method contains yield return statements to return successive elements in the asynchronous stream. After that, in order to consume that method, you need to add <strong>await<\/strong> keyword before <strong>foreach<\/strong> like below to loop through the elements of the stream.<\/p>\n<pre><span style=\"color: #333399\">await<\/span> <span style=\"color: #333399\">foreach<\/span>(<span style=\"color: #333399\">var<\/span> <span style=\"color: #800080\">query<\/span> in getQueriesAsync(<span style=\"color: #800080\">filter<\/span>)\r\n{\r\n   <span style=\"color: #333399\">Console<\/span>.<span style=\"color: #333399\">WriteLine<\/span>(<span style=\"color: #800080\">query<\/span>);\r\n}<\/pre>\n<h3><strong>Many more interesting features:<\/strong><\/h3>\n<ul>\n<li>Switch expressions<\/li>\n<li>Recursive patterns<\/li>\n<li>IEEE Floating-point improvements<\/li>\n<li>Default implementations<\/li>\n<li>More patterns<\/li>\n<\/ul>\n<p>You can see the full list here:<\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-8\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-8<\/a><\/p>\n<h1><strong>What\u2019s next?<\/strong><\/h1>\n<p>If you want to know the full list of new features in .NET Core 3. You can dig into more details by following the links in the references section below.<\/p>\n<p>By releasing this generation of .NET Core, Microsoft strongly believed it is a stable and ready-to-use version of .NET Core and recommended many businesses that they can now confidently use .NET Core 3 in their premises. But the future in the .NET family is .NET 5 which will be expected to be release in late 2020. Therefore, the roadmap of .NET will .NET 5, 6, 7, not .NET Core anymore. You do not have to worry about the compatibility between .NET Core 3 and .NET 5 much. Because .NET 5 is expected to be a <strong>unified platform<\/strong> of .NET framework and .NET Core.and targeting Windows, Linux, macOS, iOS, Android, and more.<\/p>\n<h1>References<\/h1>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/whats-new\/dotnet-core-3-0\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/core\/whats-new\/dotnet-core-3-0<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/release-notes\/aspnetcore-3.0?view=aspnetcore-3.1\">https:\/\/docs.microsoft.com\/en-us\/aspnet\/core\/release-notes\/aspnetcore-3.0?view=aspnetcore-3.1<\/a><\/p>\n<p><a href=\"https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-8\">https:\/\/docs.microsoft.com\/en-us\/dotnet\/csharp\/whats-new\/csharp-8<\/a><\/p>","protected":false},"excerpt":{"rendered":"<p>.Net Core is a free and open-source cross-platform software framework for Windows, Linux and macOS. .NET Core 3.0 was announced on May 7, 2019 and was officially released on September 23, 2019 and the later version .NET Core 3.1 was released just a few months later, on December 3, 2019. The .Net Core team has made many improvements and new features in this version.\u00a0Let\u2019s find [&hellip;]<\/p>\n","protected":false},"author":18,"featured_media":3490,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_mi_skip_tracking":false,"footnotes":""},"categories":[4,71],"tags":[],"class_list":["post-3196","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-news","category-it-tec"],"_links":{"self":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/posts\/3196","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/users\/18"}],"replies":[{"embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/comments?post=3196"}],"version-history":[{"count":0,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/posts\/3196\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/media\/3490"}],"wp:attachment":[{"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/media?parent=3196"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/categories?post=3196"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.briswell-vn.com\/en\/wp-json\/wp\/v2\/tags?post=3196"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}