The .NET Stacks #66: 🧀 Who moved my cheese?

This week, we talk about the impact of the brand new .NET 6 templates, and what that means for you.

Dave Brock
Dave Brock

I know I'm a day or so late. Sorry, I was reading about Web 3.0 and still don't know what it is. Do you? After reading this, it made me want to cry, laugh, and then cry again. As if Dapr and Dapper isn't enough, now we have "dapps."

Anyway, here's what we have going on this week (or last week):

  • Who moved my cheese: New templates for .NET 6 might surprise you
  • Community spotlight: Marten v4 is now live
  • Last week in the .NET world

Who moved my cheese: New templates for .NET 6 might surprise you

As the release of .NET 6 is rapidly approaching—with .NET 6 RC2 coming out very soon with the official release next month—you might be taken aback by C# template changes. The .NET team is leveraging top-level statements and implicit using directives for some new .NET 6 templates. For example, top-level statements are helping to drive new capabilities like Minimal APIs. Microsoft has put together a new document, New C# templates generate top-level statements, and you should check it out.

With .NET 6, if you create a new console app using dotnet new console (or from Visual Studio tooling), you might expect to see this:

using System;

namespace MyVerboseApp
{
    public class Program
    {
        public static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

Think again. You'll see this instead:

// See https://aka.ms/new-console-template for more information
Console.WriteLine("Hello, World!");

Much like with top-level statements, you probably have one of two opinions: it eliminates boilerplate and makes it simpler and more beginner-friendly; or it provides too many abstractions and "I didn't ask for this." I do like top-level statements and agree it eliminates a lot of boilerplate. When it comes to using args, though, I like to see where they are being passed in and not just a magic variable.

As of now, to stay consistent with Microsoft pushing to make C# more concise and accessible, it looks like this will be the default template. You can always use the "old" program style from the terminal using framework and target-framework-override flags. This allows you to use the "old" template but force the project framework to be .NET 6.0. (It would have been simpler to pass in --leave-my-stuff-alone, but I digress.)

dotnet new console --framework net5.0 --target-framework-override net6.0

In terms of the tooling experience, the obvious answer will be to eventually introduce a checkbox in Visual Studio to enable/disable these simplified layouts. Until then, you can downgrade the target framework moniker (TFM) to net5.0.

If you don't like it, you can file an issue in the dotnet/templating repo (or chime in on a similar issue), or even create your own templates.


Community spotlight: Marten v4 is now live

Do you know about Marten? It's a popular .NET library that allows you to use Postgresql as both a document database and a powerful event store. Jeremy Miller wrote this week about the new v4 release. Jeremy got my attention with quoting "the immortal philosopher Ferris Bueller" but also highlighted the massive changes:

  • Reducing object allocations and dictionary lookups
  • LINQ support improvements
  • Better tracking for flexible metadata
  • Event sourcing improvements

It looks to be a great release, and congrats to the team and all the great contributors. Check out the GitHub repository for more details about the project.


🌎 Last week in the .NET world

📢 Announcements

📅 Community and events

🌎 Web development

🥅 The .NET platform

⛅ The cloud

📔 Languages

🏗 Design, testing, and best practices

🎤 Podcasts and videos

.NET Stacks