Prevent adding "packages" content into source control in VS 2013

Topics: General
Dec 7, 2013 at 9:14 AM
I'm using latest version of nuget update with Visual Studio 2013 to manage local dependencies between projects.

When I add a package to the project, all of the extracted files are added to the source control and show up in the Pending Changes, which is not a good idea since the Package Restore is enabled by default, and works great.
(I'm using TFS 2013 for my source control)

I tried setting disableSourceControlIntegration item in Nuget.config file, but the behavior does not change.

My question is that am I wrong to expect it not to add package content to source control? Or this is a bug? Or there is a configuration somewhere else that I'm missing?

Also, when I put the Nuget.config file physically in a folder called ".nuget", some of the settings does not get picked up (like DefaultPushSource when calling nuget.exe). But when I put the file physically beside the .sln file (and add it to a folder in the solution) it works fine. Just want to make sure this is an issue before posting it to the issue tracker.
Feb 3, 2014 at 6:57 PM
Edited Feb 3, 2014 at 6:59 PM
I am also unable to get disableSourceControlIntegration to ignore the packages being added. I have checked every NuGet.config file on my system and they are all set to true. The NuGet.config file is in a solution folder called .nuget. We are using TFS 2012 and Visual Studio 2013 Update 1. Have also tried Visual Studio 2012 Update 4.

To replicate this behavior I:
  1. Ensure the packages folder does not exist locally for the solution.
  2. Start a solution rebuild
  3. Automatic package restore starts downloading the packages.
  4. Packages show up in the pending changes. (My understanding is that they are not suppose to)
Edit: Using NuGet version 2.8.50126.400
Feb 14, 2014 at 11:46 PM
@spowser - I was experiencing the exact same behavior you described, but I was able to get around it by adding a .tfignore file with "\packages" in the file. Look for the "Create and use a .tfignore file" (towards the bottom) in this article:

http://msdn.microsoft.com/en-us/library/ms245454.aspx

Once I added this to my solution, the packages folder and its contents no longer showed up in my pending changes.
May 20, 2014 at 11:26 PM
Edited May 20, 2014 at 11:32 PM
bobsakson wrote:
@spowser - I was experiencing the exact same behavior you described, but I was able to get around it by adding a .tfignore file with "\packages" in the file. Look for the "Create and use a .tfignore file" (towards the bottom) in this article:

http://msdn.microsoft.com/en-us/library/ms245454.aspx

Once I added this to my solution, the packages folder and its contents no longer showed up in my pending changes.
Bob, can you please post your .tfignore file? For some reason, mine isn't quite right as it seems to want to add the repositories.config to TFS. Do you put the the .tfignore file in the folder directly above packages? Does the .tfignore file have to be in the solution (we don't host our packages at the solution level any more)?


scott
Dec 4, 2014 at 8:37 AM
Same here, didn't work using the nuget.config. I realize there is a workaround (which doesn't fit what the nuget docs describe @ http://docs.nuget.org/docs/reference/nuget-config-settings , though this issue here is nearly a year old. Curious if it Is being looked into? I worked around it simply by excluding that folder in TFS but would be nice if it worked as is. Thanks!!
Feb 18, 2015 at 8:04 PM
Edited Feb 23, 2015 at 8:40 PM
Here's the deal: We have to tell both NuGet and TFS to ignore the packages, because NuGet is trying to do source-control related stuff that it absolutely shouldn't be doing (bad form, Microsoft!). So you have to do two things.

First, add a file named .tfignore. It's contents should be as follows:
    \packages
Boom. That tells TFS to ignore your packages folder. Now, you would think that this would also ignore the repositories.config file. But it won't. Why? Who knows, the ways of Microsoft are strange and mysterious. Actually, I think it's part of the NuGet stuff I outline below, but if that ever gets fixed in the future and you want to keep the repositories.config file instead of letting VS regenerate it, you should be able to use this:
    \packages
    !\packages\repositories.config
OK, so now we have out .tfignore file and TFS is ignoring your packages. Everything is fine, right? WRONG, because NuGet is mucking around with your source control and adding the packages to your pending changes. So now let's tell NuGet to cut it out already.

Create a folder called .nuget and put it in the root of your solution folder. Now, create a file called NuGet.config, and put it in this new folder[1]. It's contents should look like this:
    <?xml version="1.0" encoding="utf-8"?>
    <configuration>
      <solution>
        <add key="disableSourceControlIntegration" value="true" />
      </solution>
    </configuration>
OK, now TFS should be ignoring your packages!

One final thing, though: remember to add the nuget.config and .tfingore files to source control (not strictly necessary, but you want to make sure others on your team get these, and that you get it next time you do a fresh download). You also probably want to delete the packages folder from TFS if it exists there already.

[1]. The nuget.config file MUST go in the .nuget folder. Even if you already have a nuget.config file in the root of your solution folder (because, say, your company has an internal nuget feed). Yes, that means you'll have two nuget.config files, one in the .nuget folder and one in the solution root. My testing indicates that's the way it has to be.
Feb 18, 2015 at 9:01 PM
Have tried this as others have as well. It does not work. Each time I branch in TFS, the first time I build the branch it takes FOREVER to get the NuGet packages because it has to communicate with TFS for each file.
Feb 23, 2015 at 8:41 PM
I added some stuff to my above answer. Give it a go and let me know if it doesn't work for you. It does for me. :)
Feb 23, 2015 at 11:23 PM
Edited Feb 23, 2015 at 11:25 PM
So some good news. It's working now.

What I had and what I changed:

I had a .nuget folder in the solution and a NuGet.config file correctly configured inside of it when viewing it from within Visual Studio. The file showed as being at the same level as the solution file but DID NOT show as being inside of the .nuget folder in Windows File Explorer. I had to create a .nuget folder at the same level as the solution file by giving it a name of ".nuget." and Windows then chops off the trailing "." I then copied the NuGet.config into the folder and added it as an existing item to the solution. This must be the difference in what is required to make it work. Hope this helps someone else.

Edit: Please Microsoft, clean this up. Things shouldn't be this hard to get working.
Mar 19, 2015 at 8:33 PM
I got so tired of having to do this for my projects that I published a nuget package that will generate these files for you: DisableSourceControlIntegration-TFS
Everything is done in powershell in the init.ps1, and it is up on github.
Apr 21, 2015 at 3:10 PM
Edited Apr 21, 2015 at 3:59 PM
Since this forum is deprecated, I created an issue for this at GitHub.