How to keep packages folder out of TFVC

I have recently noticed a lot of questions about ignoring the packages folder when using Team Foundation Server Version control. I read a lot of solutions but none seemed to work for me.  Then I realized I needed a little bit of information from all the solutions to get it to work.  In this post I will explain exactly how I got TFVC to ignore my packages folder.

At the solution level create a folder named .nuget.  You have to create this folder from Source Control Explorer in Visual Studio because you cannot create a folder the begins with a period in Windows Explorer. 

  1. Open Source Control Explorer
  2. Navigate to the folder with your .sln file
  3. Right-click the background
  4. Select New Folder
  5. Name the folder .nuget

Create a file named nuget.config in the .nuget folder.

  1. Select File / New / File…
  2. Select XML File
  3. Click Open
  4. Copy and paste the text below into the file:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
       <solution>
          <add key="disableSourceControlIntegration" value="true" />
       </solution>
    </configuration>
  5. Press Ctrl+S
  6. Navigate to the .nuget folder
  7. Name the file nuget.config
  8. Click Save

Now we need to create the .tfignore file at the solution level.

  1. Right-click on the solution
  2. Select Add / New Item…
  3. Select Text File
  4. Name the file .tfignore
  5. Copy and paste the text below into the file:
    packages
  6. Save all the files
  7. Check both .tfignore and nuget.config files into source control
  8. Close Visual Studio

Now you can restart Visual Studio and open your solution.  Now when you add NuGet packages they will not be added to source control.  I also recorded a video for this that you can view below.

Comments (9) -

  • Dave Shaw

    5/24/2016 8:24:35 PM | Reply

    Hi Donovan,
    I'm not about "VS15", but VS 2012-2015 seem to have a problem that when VS does a package restore as part of a build, TFVC pends the packages as adds.

    We've tried all of the above, but no luck. I followed up the following SO comment thread with Ed in email and he confirmed in TFVC it is expected for "historical reasons":
    stackoverflow.com/.../tfs-keeps-adding-my-nuget-packages

    The solution I have is to add "packages" folder to source control, but cloak it in our workspaces.

  • David

    5/27/2016 3:44:57 PM | Reply

    Hey Donovan,

    I noticed you didn't made the nuget.config part of the solution or made TFVC aware of it. Will it don't work otherwise? other members of the team are supposed to create this file themselves?, or should it be added via source control explorer so everyone on the team has it?

    Thanks!

    • Donovan

      5/30/2016 2:58:17 PM | Reply

      They don't have to be apart of the solution but they do need to be checked into TFVC.  I updated the post to instruct you to check into source control.  Thanks for catching that.

      • Jerry Neal

        5/31/2016 7:23:32 PM | Reply

        Thanks for the youtube video and blog post. I got blocked on the same issue until I saw this blog comment. Probably need to add the same update to the youtube video.
        Thanks!

  • Chris Keith

    5/30/2016 2:45:04 PM | Reply

    The \packages folder has the file repository.config which contains pointers to the packages.config files for each in the solution. If automatic restore is used, NuGet will create the appropriate nuget.config and package folder without including the packages into source control.

  • Issa Fram

    5/30/2016 7:10:21 PM | Reply

    Are .tfignore files something new?

    Never had to use them before for this problem.  Ignore files have typically been used for Git and other source control systems, but I have never used them explicitly for TFSVC.

    • Dave Shaw

      6/4/2016 4:06:54 PM | Reply

      Issa, .tfignore files are new in TFS 2012, and work best with local workspaces where new files in your  workspace are automatically detected by VS and you are prompted to add them to TFVC. The .tfignore file is what will keep your bin/obj files appearing in the list of files that you are prompted to add. The work pretty much the same as .gitignore files.

  • Alex

    1/16/2019 10:52:33 PM | Reply

    thanks! that helped a lot!

Add comment

Loading