Creating a .gitignore file using the .NET Core SDK

Creating a .gitignore file using the .NET Core SDK

See how simple it is to create a .gitignore file for your next project using the .NET SDK.

I recently saw a tweet from fellow Kentico MVP Brian McKeiver about creating a .gitignore file using the .NET SDK. His question being why he'd not known it was a thing before now. Well, neither had I, and I wanted to take a look at it as it sounds like quite a time/life saver.

So, when did this become a thing? Looking at the .NET Core SDK documentation, we can see that back in September of 2019, Microsoft release the 3.0 SDK. This obviously had quite a lot of additions, and some of those were some new templates for the dotnet new command. 

The list of additional features in 3.0 is as follows:

  • WPF Application
  • WPF Class library
  • WPF Custom Control Library
  • WPF User Control Library
  • Windows Forms (WinForms) Application
  • Windows Forms (WinForms) Class library
  • Worker Service
  • Razor Component
  • Blazor Server App
  • ASP.NET Core gRPC Service
  • dotnet gitignore file
  • Dotnet local tool manifest file
  • Protocol Buffer File

Obviously the one that I care about here is dotnet gitignore file. It's a realy easy command to use, but it can save you from some of the basic mistakes when creating an new project.

Running the command just consists of the following:

dotnet new gitignore

There are no other options here, what you're going to get is a fairly comprehensive .gitignore (I've listed it out at the end of this article). In terminal, you'll see something like this:

Typically you'll have a .gitignore file that you might copy and paste from project to project, or you might build it up as you go along. The later of those two option is always more prone to error, so being able to create this as a starter is certainly going to be helpful for that next new project!

The generated .gitignore file

Originally publised at https://dev.to/mattnield/building-up-your-content-model-39bo