Share this post
  

Playing with .NET 6 preview, C# 10 and Docker

.NET 6 is coming on November 2021! Here are some and some interesting links to keep an eye on from recent announcements from Microsot Build 2021 Conference. A lot of great stuff coming up!

Long time, no blogging!

It has been a while from last time I blogged. I’m really having a great time and fun since I joined Microsoft to work remotely, and it’s always great to take some time back on my notes to share some cool tech with the community. This time, .NET 6 stuff!

ICYMI: Here is the link to my previous post on joining Microsoft: 2020/12/07/Work at an awesome place. I’m joining Microsoft!

Play with dotnet 6 and docker

Let’s get started.

Here is a summary of what’s coming with .NET 6 tooling:

  • C# 10 preview features
  • Minimal APIs support
  • Linq & EF Core 6 previews
  • .NET MAUI
  • And more to come

At the time of publishing this post, there are 6 official previews released of .NET 6 (with Preview 7 going out soon!). The good thing is that tooling is going pretty much the same across those (VS Code support, dotnet build, run, etc) while Hot Reload is coming across .NET and Visual Studio 2022 on 64bit is now on Preview!

If you want to give it a try, I took some time to put it altogether in a new GitHub repo, which can be used with GitHub Codespaces and Docker so you don’t have to install locally in your machine!

https://github.com/stvansolano/dotnet6-preview/

.NET 6 preview repo link

There are two ways for using the repo:

  1. GitHub Codespaces: If you have GitHub account with Codespaces support (public preview available, going GA soon!), you can just open it from “Code” button, then > “Open with Codespaces”. Tip: You can use the repo as a template for creating your own repo!
  2. ** Fork/clone locally**: You can use VSCode with the repo and install the Visual Studio Code Remote Development extension, Docker and open the folder in container.

More details: Visual Studio Code Remote Development

By opening from GitHub either VS Code (latest version preferarly) you would be ready to go!

Project structure & samples

  • /ConsoleApp (Minimal Console app with C# 10 / .NET 6 support)
  • /ConsoleApp.EntityFramework (.NET 6 + EF with SQLite)
  • /ConsoleApp.Linq (Some new LINQ coming features, no EF)
  • /WebApi (Minimal Web API with C# 9 / .NET 6)
  • /WebApi-Swagger (Minimal Web API with swagger support)
  • CI Dockerfile (yes! We have NuGet support and Docker SDK and Runtime images available!)
  • GitHub Actions with .NET 6

Creating a new Minimal Web API

dotnet new web -o src/WebApi

Here is how the Program.cs file looks like:




Then Run it

dotnet run --project WebApi/WebApi.csproj

Important: If you are running it from GitHub Codespace, make sure you have dotnet in your $PATH

export DOTNET_ROOT=$HOME/dotnet \ && export PATH=$PATH:$HOME/dotnet

C# 10 Global usings

With C# 10 you can place usings into a separate file (e.g Usings.cs) and keep the compiler happy across your clases. Event better, duplicated using statements can be removed and put them in 1 single file:




Getting some hands on GitHub Actions .NET 6

You can take advantage of the .NET 6 preview builds and use them as Docker images from Docker Hub. Both SDK and Runtime can be used accordingly:

https://github.com/stvansolano/dotnet6-preview/blob/main/.github/workflows/dotnet6-docker-build.yml




Running the GitHub action

Make sure to put it under /.github/workflows folder so it can be executed automatically on every push on the repo.

Here is my dotnet6-docker-build.yml file output:

GitHub action

.NET 6 Preview blogs:

Don’t forget to open issues in the stvansolano/dotnet6-preview repo in case something may need ny attention, and if you like it, give it a star. Happy coding!

P.D: I would be making progress and introduce changes in the repo as new previews got out. So stay refreshing/F5-ing!

-Esteban

Share this post
  

Software Engineer at Microsoft | Former MVP, Certified developer
@stvansolano
More about me

 Browse by tag

 Xamarin

 

 DotNet

 

 Spanish/Español

 

 Productividad

 

 Open Source

 

 Microsoft

 

 AppCenter

 

 DevOps

 

 Conferences

 

 Google

 

 Docker

 

 Kubernetes

 

 XamarinDiplomado

 

 ASP.NET

 

 Web Apps

 

 Yeoman

 

 HTML5

 

 REST

 

 Web API

 

 Meetup

 

 Freelance

 

 Android

 

 Mobile

 

 CodeMentor

 

 OSS

 

 containers

 

 Codespaces

 

 Github

 

 React

 

 MVVM

 

 iOS

 

 FSharp

 

 MVP

 

 Comunidad

 

 Azure

 

 AI

 

 Exam

 

 Certification

 

 Rifa

 

 Markdown

 

 GitHub

 

 Backend

 

 Online

 

 WebAPI

 

 MacOS

 

 Asp.Net Core

 

 Taller

 

 Charla

 

 Git

 

 WordPress

 

 Spanish/English

 

 UX / UI

 

 Realm

 

 Bootcamp

 

 Productivity

 

 VisualStudio

 

 Contenedores

 

 M365

 

 MAUI

 

 .NET

 

 Serverless

 

 AspNet

 

 DevDays

 

 Maui

 

 Workshop

 

 XamarinForms

 

 Cloud

 

 NetCore

 

 SignalR

 

 CosmosDB

 

 MachineLearning

 

 Python

 

 MVPSummit

 

 YouTube

 

 VS4Mac

 

 Linux

 

 Windows

 

 Career

 

 OpenSource

 

 TestCloud