简体   繁体   English

.gitignore NuGet 排除包/包含包/repositories.config

[英].gitignore NuGet exclude packages/ include packages/repositories.config

I'm trying to create a .gitignore for a Visual Studio project that uses NuGet.我正在尝试为使用 NuGet 的 Visual Studio 项目创建一个 .gitignore。 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.这将忽略包文件夹中的所有内容,并且不包括包/repositories.config。

What am I doing wrong?我究竟做错了什么?

/packages/
!packages/repositories.config

You can also add a .gitignore in the packages folder:您还可以在包文件夹中添加.gitignore

*
!repositories.config
!.gitignore

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.而且我认为维护多个 .ignore 文件是一个糟糕的解决方案。

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: Visual Studio的官方.gitignore 模板推荐了以下解决方案:

# 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 :-)编辑:您可以使用https://www.gitignore.io为您喜欢的项目生成 .ignore 文件:-)

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.) (与@manojlds 的答案相同,只是删除了第一行中的星号。这对我不起作用。)

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.不确定除了 repositories.config 之外还有哪些其他文件可能会出现在那里,或者它们是否应该包含在存储库中。

See also .gitignore Syntax: bin vs bin/ vs. bin/* vs. bin/**另请参见.gitignore 语法:bin vs bin/ vs. bin/* vs. bin/**

对我来说只有这有效:

**/packages/**

If you want to do it correctly for ALL NUGET Temp artifacts如果您想对所有 NUGET Temp 工件正确执行此操作

Add this code to your .gitignore将此代码添加到您的.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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM