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"?>
          <add key="disableSourceControlIntegration" value="true" />
  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:
  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 (7) -

  • 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":

    The solution I have is to add "packages" folder to source control, but cloak it in our workspaces.
  • 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?

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

Add comment