繁体   English   中英

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

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

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

\packages/*
!packages/repositories.config

这不会忽略文件夹中的任何内容。 一切都在添加上上演。 我也试过:

packages/
!packages/repositories.config

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

我究竟做错了什么?

/packages/
!packages/repositories.config

您还可以在包文件夹中添加.gitignore

*
!repositories.config
!.gitignore

我遇到了同样的问题。

以上解决方案都不适合我。 而且我认为维护多个 .ignore 文件是一个糟糕的解决方案。

我就是这样解决的。

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

组合两个星号将匹配任何文件夹字符串。 我认为省略星号会产生同样的效果,但显然我(我们)错了,因为它似乎不起作用。

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

编辑:您可以使用https://www.gitignore.io为您喜欢的项目生成 .ignore 文件:-)

这对我有用。

#NuGet
packages
!packages/repositories.config

(与@manojlds 的答案相同,只是删除了第一行中的星号。这对我不起作用。)

我发现这个简单的模式有效。

/packages/*/

它应该忽略根包目录中的所有目录,但包含那里的所有文件。 不确定除了 repositories.config 之外还有哪些其他文件可能会出现在那里,或者它们是否应该包含在存储库中。

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

对我来说只有这有效:

**/packages/**

如果您想对所有 NUGET Temp 工件正确执行此操作

将此代码添加到您的.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