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!
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!
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!
There are two ways for using the repo:
- 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!
- ** 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!
- /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
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
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:
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:
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:
- Preview 7: (Coming soon)
- Preview 6: https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-6/
- Preview 5: https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-5/
- Preview 4: https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-4/
- Preview 3: https://devblogs.microsoft.com/dotnet/announcing-net-6-preview-3/- EF Core 6 preview: https://devblogs.microsoft.com/dotnet/announcing-entity-framework-core-6-0-preview-5-compiled-models/
- .NET MAUI: https://devblogs.microsoft.com/dotnet/announcing-net-maui-preview-5/
- ASP.NET 6 preview: https://devblogs.microsoft.com/aspnet/asp-net-core-updates-in-net-6-preview-5/
- C# 10 what’s new: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-10
- C# 9 & preview: https://docs.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-9
- C# guide: https://docs.microsoft.com/en-us/dotnet/csharp/
- C# Language Versioning: https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/configure-language-version
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!