Drop a gitignore file as part of project/sln templates
See original GitHub issueMy workflow for creating a new project with dotnet new
is generally something like this:
mkdir MyNewProject
cd MyNewProject
dotnet new console
git init
- Browse to github.com/github/gitignore
- Find
VisualStudio.gitignore
- Click “Raw”
- Copy the content
- Edit a new
.gitignore
file in the repo - Paste
- Save
(I only recently realized that I could use dotnet new console -n MyNewProject
to collapse steps 1-3)
(And yeah, I could save time with the gitignore stuff, but I am a lazy engineer and want tools to do things for me 😃)
Whereas, when I play with rust
and use cargo
, my workflow is this:
cargo new MyNewProject
The results are the same, a single project is created in a new directory with a Git repo and an appropriate gitignore file. I think we could simplify the dotnet new
experience quite a bit.
I like that the cargo
cli has decided to be Git-by-default. I realize that doesn’t work in all environments but I think that the command-line audience very frequently wants a git repository and gitignore file. Cargo also has a --vcs
option which allows you to choose git
, hg
, or none
, and a config system that allows you to have a user-level default if you aren’t using git
.
This would also have to be conditional on detecting if the newly-expanded template is already in a git repo.
Issue Analytics
- State:
- Created 6 years ago
- Reactions:11
- Comments:19 (13 by maintainers)
Top GitHub Comments
I don’t think we’d include one automatically - we should lean on the existing
.gitignore
item template, or allow folks to generate their own.After a bit of hunting and for anyone else interested, the problem is with dotnet pack and nuget it excludes files starting with a . so obviously .gitignore and similar files will not be part of a dotnet new project template.
To fix this I found it by digging around and seeing this mentioned in this comment https://github.com/fable-compiler/fable-templates/issues/44#issuecomment-912616778
Along with finding it here as well https://github.com/dotnet/templating/issues/2350#issuecomment-610431461
You can see there is an option/flag for dotnet pack
-NoDefaultExcludes
https://docs.microsoft.com/en-us/nuget/reference/cli-reference/cli-ref-pack#optionsAlso it could be set in a csproj file inside a propertygroup element
So if anyone else stumbles across this issue hopefully you now have a solution to get a .gitignore file to show up