Overview

  • .NET 6 is a unification platform of different .NETs into one, with a single BCL and SDK
  • Visual Studio 2022 is now x64 and has a Hot Reload feature for UIs (avoiding restarts)
  • C# 10 with new top-level statements, ASP.NET Core 6, EF Core 6, and C++ updates
  • ASP.NET template updates for MVC, Razor Pages, Angular, React and other JS frameworks
  • New Minimal APIs and Blazor extensions, WebAssembly Ahead-of-time (AOT) compilation
  • Maui (RC1), a cross-platform native UI dev platform that evolved from Xamarin.Forms
  • Big overall performance improvements, especially around file I/O (FileStream rewrite)

Recources

Visual Studio 2022

  • A new refreshed UI, with new icons, new font (Cascadia), and coloured tabs by project
  • Visual Studio is now using x64 architecture!
  • A new Hot Reload feature/ button for running apps – no more stopping and rebuilding projects while debugging! Code changes are visible in running apps right away
    • Hot Reload is available for WPF, Blazor, and ASP.NET Core MVC with CSS
    • Hot Reload can also be bound to the Save button
  • New and updated project templates, including ASP.NET Core 6 and Angular
    • E.g., top level statements in Program.cs
      • Startup.cs + Prgram.cs = Program.cs
  • IntelliCode – auto code snippets/ templates accessible with a [tab] key
  • Refactoring improvements, e.g., sync namespaces, file scope namespaces
  • XAML Live Preview, Improved Git experience

C# 10

  • Some New Features
    • Global using statements (types available in the entire solution)
      • Note: it’s a good idea to maintain these in GlobalUsings.cs
    • Implicit usings – when enabled there’s no need to ref System; etc.
    • File-scoped namespaces (improved code nesting)
    • Extended property patterns (nested properties or fields within a property pattern)
    • Lambda expressions improvements
    • Const interpolated strings
    • Record structs enhancements (e.g., sealing ToString()) 
    • Generic attributes
    • Assignment and declaration in the same deconstruction
    • AsyncMethodBuilder attribute on methods is now possible
    • DateOnly and TypeOnly data types
    • New Environment API features, including find Process ID and Process Path
    • new LINQ Methods e.g., Chunk() on IEnumerable<>, MinBy() and MaxBy()
    • ThrowIfNull, a new timer, parallel for each async, and more!
  • Release Notes on Github

// global namespace
namespace MyNamespace;

// generic attribute example
public class GenericAttribute<T> : Attribute { }

[GenericAttribute<string>()]
public string Method() => default;

// record struct example
public record Person(string FirstName, string LastName);

public static void Main()
{
    Person person = new("Joe", "Doe");
    Console.WriteLine(person); // output: Person { FirstName = Joe, LastName = Doe}

    // assignment and declaration in same deconstruction
    int x = 0;
    (x, int y) = point;
}

ASP.NET Core 6

  • ASP.NET Core 6
    • ASP.NET Core MVC – server-side web apps using the MVC model
    • ASP.NET Core Razor Pages – simpler server-side web apps
    • ASP.NET Core Blazor or Blazor – client-side apps with C#
      • Blazor code now compiled into WebAssembly
      • Error boundaries, e.g., at the component level
      • Blazor (cross-platform) MAUI apps, dynamic widgets and more!
    • ASP.NET Core APIs – including minimal API
  • Breaking Changes/ Compatibility for upgrading existing apps

Minimal APIs
  • A very compact template to create APIs
    • Based on top-level statements and Program.cs
    • More functional approach to building applications than the traditional OOP model
var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddScoped<IMyDataRepo, MyDataRepo>();

var app = builder.Build(); 

app.UseSwaggerUI();

app.MapGet("/data/all", async ([FromServices] IMyDataRepo repository) => 
{
  return repository.GetAll();
});

app.Run();

Cross-platform Development with .NET Maui
  • MAUI = Multi-platform App UI
    • Cross-platform Mobile and Desktop apps
  • .NET 6 replacement of Xamarin
    • Legacy .NET mobile (iOS and Android) development framework based on the mono framework
  • C# and XAML native
  • SIngle API combines with platform-specific frameworks
  • Single project structure
    • with access to platform-specific APIs
  • Easy platform-specific deployment options