.NET Conf 2020
It is that time of year again. Microsoft just finished the .NET Conf 2020 talks and there is a lot here to unpack. With the pending merge of the .NET Core and .NET Framework projects into .NET 5, we knew this was going to be a big year for developers. And Microsoft did not disappoint. Follow along for some overviews and deep dives into what Microsoft announced, and what that means for development teams and your custom software going forward into 2021.
.NET 5 Release
Microsoft released .NET 5 to the world this week, and that means a lot of new changes for developers and companies that rely on both the .NET Framework and .NET Core. .NET 5 is a Current release for the .NET team, meaning that it is not a recommended upgrade for those looking to use the LTS release cycle.
Support for .NET 5 is expected to last through early 2022, with .NET 6.0 being the next LTS release planned in late 2021. This means that most teams will probably stick with .NET Core 3.1 or .NET Framework 4.8 for the time being in order to stay on the more stable track. While many teams will not be migrating to .NET 5, there are still some important improvements to be aware of, and how they will impact your code down the road.
With the release of .NET 5, this also means that .NET Framework 4.8 is the last major version of the .NET Framework. No new features will ever be added to the .NET Framework, and .NET is now back on a single framework path with all new features and functionality being added to .NET 5 and later.
Single File Applications & Containerization Changes
Self-contained, single file exe’s without needing to install the .NET Framework or .NET Core redistributable packages are a big update from the .NET team. ClickOnce with .NET 5 allows building an application to a self-contained executable that can be distributed with all the necessary libraries compiled into the EXE file. This allows for easy portable deployments of applications to environments where users may not understand the requirement to install .NET Framework, or where security controls prevent the installation or update of the .NET requirements. This has been a feature that many developers have been requesting from Microsoft for many releases, and .NET 5 brings this much-desired feature to the platform. Find out more about single file applications here - Single file application - .NET Core | Microsoft Docs
On the containerization front, Microsoft has introduced support for deploying self-contained .NET applications to docker containers with a new dependency only image. This allows for further shrinking of docker apps to enhance deployment density of microservices. By packaging your .NET 5 application with the self-contained flag, and turning on Assembly Trimming, you can dramatically lower the final size of your docker images. Combining these new features with the .NET Alpine images, you can get your docker containers down below 100MB in size now. This leads to a dramatically faster startup time in docker for .NET 5 apps as compared to .NET Core 3.1. For details around how to make these changes to your docker scripts, see the sample from the .NET team - dotnet-docker/samples/dotnetapp at master · dotnet/dotnet-docker (github.com)
Microsoft has announced the next evolution for Xamarin.Forms. .NET MAUI (Multi-platform App UI) is the next step towards creating a modern cross-platform native UI framework for the .NET platform. To be released in Preview on .NET 5, it is slated for full release on .NET 6. The migration of Xamarin.Forms apps should be relatively easy, while existing Windows XAML apps might take more work. The goal with the MAUI project is to have a single project experience for all devices, mobile, and desktop. This should dramatically reduce development costs for cross-platform apps and increase developer productivity. Also new in MAUI is support for the increasingly popular MVU (Model-View-Update) pattern. To learn more, visit the GitHub repo for the MAUI project - dotnet/maui: .NET MAUI is the .NET Multi-platform App UI, a framework for building native device applications spanning mobile, tablet, and desktop. (github.com)
Windows ARM64 Support
.NET Core 3.1 was the introduction of .NET to Windows ARM64. The implementation was basic, and performance left a lot to be desired. With .NET 5, the team has brought a proper full performance implementation of .NET over to the Windows ARM64 platform. Performance on the ARM64 hardware is much closer now to X86 performance of .NET code. These gains also translate to the new Apple M1 chip for the new MacBook Air. Performance gains up to 2X are seen in ARM64 now, with even more improvements set to be delivered in .NET 6 in 2021. Metrics and details on new instruction support and benchmarks are available ARM64 Performance in .NET 5 | .NET Blog (microsoft.com)
New Language Features in C# 9
With the release of .NET 5, we also get new features added to the C# 9 language. The biggest new feature among them is Records. Records are immutable reference types that behave like value types. With records, you get several synthetic properties created by the compiler for your object by default. Methods for value-based equality comparisons, Copy and Clone members, GetHashCode() override, and ToString() implementations are all generated by the compiler. This can dramatically reduce the boilerplate code needed to support simple objects that do not have a lot of business logic necessary.
Records also support proper inheritance and can be sealed as well to prevent further derivation from outside classes. Records can be declared in a more concise format, called positional records. This reduces the boilerplate code even further by eliminating property declarations and constructors; replacing them with a simple declarative structure.
You can also add brackets and include methods in this format as well, while still gaining the concise formatting for properties and constructors.(download snippet)
In addition to this, the compiler produces a Deconstruct method for positional records, allowing you to break a record into its individual components.
'With' expressions are also new to C# 9, and is a new keyword reserved in the language for use with records. The with keyword allows you to copy a record to a new instance while modifying one or more of the properties. All references are copied to the new instance, so that modifications to any copy are not reflected back, and modifications after the copy only stay on the original.
Init only setters are a new language feature that allow you to define setters on properties of a class to be used only during the initializer syntax to set values of properties you wish to not change during the lifecycle of an object. This language feature allows for keeping light and clean Constructors, while allowing for setting values of an object only during creation. Attempts to modify the value of a property with an init setter after initialization will throw a compiler error, so these can be very useful for enforcing code styles and conventions in a team.
Find details on these changes and more here - What's new in C# 9.0 - C# Guide | Microsoft Docs
Blazor WASM with .NET 5 performance has improved up to 3X over .NET Core 3.1. A lot of attention was paid to time to first render in Blazor. The dreaded “Loading” screen from Blazor is near eliminated on all but the slowest of connections now as the application streaming performance has been dramatically increased.
New in .NET 5, Blazor WASM can now utilize prerendering of components on the server-side to reduce the amount of rendering required on the client-side. This allows pre-rendering of pages on the server into static HTML, then later enhanced on the client-side with Blazor WASM. Previously, Blazor developers had to choose between Blazor Server-Side or Blazor WASM and performing all rendering on either the server or the client. Now the load can be shared between the two to enhance performance and reduce load on both ends of the application hosting.
Lazy loading dependencies
No more do you need to load all dependencies in your Blazor app at startup. Dependencies can now be lazy-loaded upon request while the application loads. This allows for streaming components, libraries, and other dependencies as your user navigates the application instead of having to front-load the entire application. This is one of the key technologies that allowed the Blazor team to dramatically reduce initial load time in Blazor WASM apps.
Component virtualization in Blazor increases rendering performance of your components by restricting rendering to just the currently visual components on screen. This allows you to take large datasets with thousands of records and reduce rendering to just the currently visible elements in order to reduce the load on the client’s device.
New XAML Experience and Hot Reload 2.0
New to the Xamarin development experience is Hot Reload. Now changes to XAML code reload immediately in your Xamarin debugger to allow for a much better productivity for visual developers. Microsoft has also introduced new debugging utilities to assist in building your Xamarin apps using XAML. The new XAML Binding Failure tool assists in debugging XAML errors easily, eliminating a common issue with tracking down missing data on a Xamarin app.
Developing iOS apps on Windows
The team at Microsoft has finally closed the last remaining gap for Windows-based mobile developers in Visual Studio. Previously, debugging apps on iOS required a developer to either use Visual Studio on Mac, or use a Mac bridge to connect their iOS device for debugging applications. Now with Reflector, you can AirPlay your iOS device to your PC and use the new Hot Reload for iOS feature to connect your iOS device to Visual Studio and deploy custom applications. Deployment to the Apple Store still requires use of a Mac, but App Center can be used to overcome this requirement. This opens a door to developers that do not have access to a Mac to build, test, and deploy to Apple devices which have previously been a walled garden that was difficult to access without access to Apple hardware.
.NET Roslyn Analyzers
Use of Roslyn Analyzers in previous versions of Visual Studio meant hunting through GitHub repos to find the analyzers and determining how to add them to your project manually. With the release of Visual Studio 2019 16.8, Roslyn Analyzers are now included out of the box for C# projects. This allows for easier static code analysis to assist in validating code against C# best practices. You can change the settings for the Roslyn Analyzers easily using the .editorconfig file in your Solution. For more details on how to use Code Styles and Roslyn Analyzers see EditorConfig settings - Visual Studio | Microsoft Docs
New Git experience
Visual Studio 16.8 brings the “New Git Experience” that has been in preview for the past year into full support. Conflict merge experiences are greatly improved in VS 16.8. Replacing the old “target” and “incoming” labels on windows are now branch names. This is a much welcome change that should mean you will not need to leave Visual Studio as often to manage your git repositories cleanly. See more about the new Git experience in Visual Studio 2019 16.8 - The Git experience in Visual Studio | Microsoft Docs
Linux Debugging and Unit Test Targets
Visual Studio 2019 16.8 allows for targeting external deployments for unit tests and debugging on new systems. This includes new support for Linux Remote Debugging with .NET 5 and Unit Tests running on Linux using Docker containers and other remoting technologies with .NET 5.
Future of .NET on Mobile
Coming with .NET 6, the entirety of the .NET ecosystem will be folded into .NET. Mono, Xamarin, .NET Standard and .NET Core all become .NET 6. The first step in this was included with .NET 5 with the merging of .NET Framework, .NET Core, and .NET Standard into the singular .NET 5 SDK. This will lead to greater code portability across platforms and targets. With .NET 6, new targets for Android, iOS, and other platforms will arrive to replace the Mono targets.
Project Tye is a new IaC project from the ASP.NET team out of Microsoft. Tye is a series of tools and a framework for building and deploying modern containerized microservice applications. Tye is a great tool for local dev environments, allowing you to easily spin up an application and all its dependencies on your local development machine without needing to install things like SQL Server or Redis. Applications are run using docker containers with an option to utilize a local or remote Kubernetes cluster, and Tye provides a dashboard for metrics, logging, and assisting in debugging of the application stack. In addition, Project Tye adds Service Discovery to .NET 5 to assist in meshing together microservices without needing to add external service discovery software like Consul. Finally, Project Tye, also allows for production deployment to Kubernetes clusters without needing to use Kubernetes charts or a templating engine such as Helm. This means that multiple chart languages between local development and production environments do not need to be maintained.
2020 has been a big year for the .NET team, and .NET 5 gives us a great glimpse into the future of the .NET ecosystem. Changes continue to head in a community-driven direction, with the shift to open source driven development of the platform continuing to show the advantages of this process change. We continue to see growth of the platform in a direction that will increase productivity and reduce support costs, while continuing to increase performance across all platforms with .NET. While many teams will not be able to shift to .NET 5 and will prefer to skip to .NET 6, those that do will find that tooling is much improved and continues to be industry-leading. To watch any of the aired sessions on-demand, examine conference slides, and demos from presenters head over to .NET Conf 2020 (dotnetconf.net)