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

前端 未结 5 1664
离开以前
离开以前 2021-01-30 00:25

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

\\packages/*
!packages/repositories.config
相关标签:
5条回答
  • 2021-01-30 01:05
    /packages/
    !packages/repositories.config
    

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

    *
    !repositories.config
    !.gitignore
    
    0 讨论(0)
  • 2021-01-30 01:06

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

    0 讨论(0)
  • 2021-01-30 01:26

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

    0 讨论(0)
  • 2021-01-30 01:27

    For me only this worked:

    **/packages/**

    0 讨论(0)
  • 2021-01-30 01:28

    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/**

    0 讨论(0)
提交回复
热议问题