. gitignoreNuGet 排除软件包/include 软件包/Repositories.config

我正在尝试为一个使用 NuGet 的 Visual Studio 项目创建一个. gitignore,它目前包含:

\packages/*
!packages/repositories.config

这不会忽略文件夹中的任何内容。所有内容都会在一个添加上显示。我还试过:

packages/
!packages/repositories.config

这将忽略包文件夹中的所有内容,并且不包括包/Repositories.config。

我做错了什么?

48577 次浏览
/packages/
!packages/repositories.config

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

*
!repositories.config
!.gitignore

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.)

I found this simple pattern works.

/packages/*/

It should ignore all directories in the root packages directory, but include all files there. Not sure what other files than repositories.config might appear in there or whether they should be included in the repository.

See also .gitignore Syntax: bin vs bin/ vs. bin/* vs. bin/**

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 :-)

For me only this worked:

**/packages/**

If you want to do it correctly for ALL NUGET Temp artifacts

Add this code to your .gitignore


# Ignore all my NuGet temp Packages
*.nupkg
# NuGet Symbol Packages
*.snupkg
# The packages folder can be ignored because of Package Restore
**/[Pp]ackages/*
# except build/, which is used as an MSBuild target.
!**/[Pp]ackages/build/
# Uncomment if necessary however generally it will be regenerated when needed
#!**/[Pp]ackages/repositories.config
# NuGet v3's project.json files produces more ignorable files
*.nuget.props
*.nuget.targets