![](/img/trans.png)
[英].gitignore NuGet packages folder at any level but include .targets file at any level
[英].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 文件:-)
我發現這個簡單的模式有效。
/packages/*/
它應該忽略根包目錄中的所有目錄,但包含那里的所有文件。 不確定除了 repositories.config 之外還有哪些其他文件可能會出現在那里,或者它們是否應該包含在存儲庫中。
對我來說只有這有效:
**/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.