Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.gitignore NuGet exclude packages/ include packages/repositories.config

I'm trying to create a .gitignore for a Visual Studio project that uses NuGet. It currently contains:

\packages/*
!packages/repositories.config

This does not ignore anything in the folder. Everything gets staged on an add. I have also tried:

packages/
!packages/repositories.config

This ignores everything in the packages folder and does not include the packages/repositories.config.

What am I doing wrong?

like image 843
Dipesh Avatar asked May 28 '12 04:05

Dipesh


3 Answers

/packages/
!packages/repositories.config

You can also add a .gitignore in the packages folder:

*
!repositories.config
!.gitignore
like image 134
manojlds Avatar answered Oct 18 '22 12:10

manojlds


I faced the same issue.

None of the above solutions worked for me. And I think it's a poor solution to maintain multiple .ignore files.

This is how I solved it.

**/packages/*
!**/packages/repositories.config

Combining two asterisks will match any string of folders. I thought leaving out asterisks would have the same effect, but apparently I (we) were wrong, as it doesn't seem to work.

The official .gitignore template for Visual Studio recommends the following solutions:

# NuGet Packages
*.nupkg
# The packages folder can be ignored because of Package Restore
**/packages/*
# except build/, which is used as an MSBuild target.
!**/packages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/packages/repositories.config

EDIT: You can use https://www.gitignore.io to generate .ignore file for your favorite project :-)

like image 22
Ali Reza Dehdar Avatar answered Oct 18 '22 12:10

Ali Reza Dehdar


This works for me.

#NuGet
packages
!packages/repositories.config

(Same as @manojlds's answer except removed the star in the first line. That didn't work for me.)

like image 33
Grant Birchmeier Avatar answered Oct 18 '22 13:10

Grant Birchmeier