DEV Community

Dave Brock
Dave Brock

Posted on • Originally published at daveabrock.com on

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

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!");
        }
    }
}
Enter fullscreen mode Exit fullscreen mode

Think again. You'll see this instead:

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

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
Enter fullscreen mode Exit fullscreen mode

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

Top comments (1)

Collapse
 
jayjeckel profile image
Jay Jeckel

I have to laugh when blockchain worshippers use web3 unironically since web 2.0 was also a term that never really meant anything and was only used by hucksters and con artists to sell snake oil.

Anyway, on topic, I for one don't care at all for the new templates. I am on the fence with global usings and file level statements to begin with, but I know I definitely don't want them as the default. Bring on that checkbox as soon as possible.