Add .gitignore to dotnet Project
Create new project from template
Using the dotnet new
command, create a application based upon the console template.
iesoftwaredeveloper:~/repos$ dotnet new console --output SimpleCmdLine/src --name SimpleCmdLine
The template "Console Application" was created successfully.
Processing post-creation actions...
Running 'dotnet restore' on SimpleCmdLine/src/SimpleCmdLine.csproj...
Determining projects to restore...
Restored /Users/iesoftwaredeveloper/repos/SimpleCmdLine/src/SimpleCmdLine.csproj (in 66 ms).
Restore succeeded.
iesoftwaredeveloper:~/repos$
Once the dotnet new
command has completed you will should have a new directory called SimpleCmdLine
in the current directory. Change to the new directory and then the src
directory and then list the files that were created.
iesoftwaredeveloper:~/repos$ cd SimpleCmdLine
iesoftwaredeveloper:~/repos$ cd src
iesoftwaredeveloper:~/repos$ ls
Program.cs SimpleCmdLine.csproj
iesoftwaredeveloper:~/repos$
You can see that the template created two files. The first is the project file SimpleCmdLine.csproj
and the other is the main file for the project called Program.cs
.
Add a .gitignore and README
To help ensure that we avoid committing files that we don't usually want in our git repos we should create a .gitignore
file. Fortunately, dotnet
can help us create a simple .gitignore
that will accommodate some common files when developing using Visual Studio. If you are using Visual Studio Code the same .gitignore
will also apply. If you are using a different Integrated Development Environment (IDE) or using a simple text editor then you will still benefit from creating the .gitignore
using this method. Many of the items are created as part of the dotnet
commands.
To create a dotnet focused .gitignore
using the dotnet new gitignore
command. While we are here I will create a basic README.md as well.
Note: The readme template is not installed by default. If you do not have it installed then dotnet will search NuGet for a matching template. I installed the template from author Rodolpho Alves named "Readme (Markdown)". You can install it using the command
dotnet new -i ARDC.Commons.Templates::0.2.1
This is entirely optional and you can certainly just manually create your own README.md
iesoftwaredeveloper:~/repos/SimpleCmdLine$ dotnet new gitignore
The template "dotnet gitignore file" was created successfully.
iesoftwaredeveloper:~/repos/SimpleCmdLine$ dotnet new readme
The template "Readme (Markdown)" was created successfully.
iesoftwaredeveloper:~/repos/SimpleCmdLine$
If you open your .gitignore
you will see that it has been populated with a myriad of rules to help avoid committing files you probably do not want in your repository.
You must be logged in to see the comments. Log in now!