43

VS2013 had a bug where NuGet would add packages as pending changes, even if you told it not to with .tfignore. There was a workaround, but it doesn't work with VS2015/NuGet3, and NuGet is back to its old tricks. Is there a "Nu" workaround? :-)

Microsoft Connect item: NuGet adds packages to TFS despite .tfignore

Community
  • 1
  • 1
Edward Brey
  • 40,302
  • 20
  • 199
  • 253
  • 6
    Not the answer you're looking for, but after smashing my head against the TFS wall for a couple years, I convinced my team that git was the way to go... `.gitignore` actually works like you'd expect :-) – kaveman Aug 15 '15 at 14:46

3 Answers3

41

It looks like this is fixed in version 3.2 RC of the NuGet Visual Studio 2015 Extension - updating to this version worked for me, at least.

A discussion about this issue can be found here where it is recommended to update from NuGet 3.1 to 3.2 RC.

Update

Version 3.2 of the extension has now been released (found here) which includes this fix.

Clarification

To get this working you need two things:

  1. A nuget.config file containing the disableSourceControlIntegration setting
  2. A version of the NuGet Visual Studio 2015 Extension that respects the disableSourceControlIntegration setting (versions from 3.2 onward should work)

As indicated in the docs:

NuGet first loads NuGet.config from the default location, then loads any file named NuGet.config starting from the root of the current drive and ending in the current directory.

This means that you can specify <solution><add key="disableSourceControlIntegration" value="true" /></solution> in the default config file for your user profile (found at %APPDATA%\NuGet\NuGet.Config) or in the NuGet config file in your solution directory, e.g., \MySolution\.NuGet\NuGet.config.

Tsahi Asher
  • 1,767
  • 15
  • 28
nick_w
  • 14,758
  • 3
  • 51
  • 71
  • 14
    I've found it easiest to add the `disableSourceControlIntegration` option to the default config file at `%APPDATA%\NuGet\NuGet.Config` like so: ` ` – dsghi Oct 28 '15 at 09:33
  • 1
    @dsghi You've just solved something for me that has been annoying me since 2013. I never knew there was a GLOBAL nuget.config file! – Riegardt Steyn Jan 04 '16 at 11:25
  • I'm on 3.2 RC and still get the error. It may be worth noting that this project was created in 2013 and migration to 2015 – dougajmcdonald Jan 06 '16 at 11:14
  • 1
    @dougajmcdonald Keep in mind that simply updating the extension probably won't solve this problem if it already exists (i.e., the packages folder is in source control already). In that case you'll need to remove the packages folder from TFS before VS will start ignoring it. – nick_w Jan 06 '16 at 11:29
  • 2
    I just did a new project with VS2015. Using 3.3.0.167 of NuGet Package Manager for Visual Studio. Upon `Add Solution to Source Control` it added the packages folder, subfolder, binaries, etc. I don't think this answer works. – Rick Glos Jan 06 '16 at 20:13
  • @RickGlos Did your new project have a nuget.config file? You'll still need one so that you can set the `disableSourceControlIntegration` setting. – nick_w Jan 06 '16 at 21:23
  • @dsghi Cheers, I've incorporated that into my answer. Can you remember which version of the NuGet extension you were using back then? Version 3.1 broke support for `disableSourceControlIntegration`. – nick_w Jan 06 '16 at 23:18
  • @nick_w File -> New Console App and then `Install SomeNugetPackage` - does not add a NuGet.config file to the solution or project folder so I went with the advice below using `%AppData%\NuGet\NuGet.Config`. I did not know about this extra file you could optionally create for the solution itself. – Rick Glos Jan 07 '16 at 22:27
  • This worked well, but didn't realize at first that it's per user, since APPDATA is a user profile. So I think this has to be copied to each programmer, on any machine they use. – goodeye Aug 14 '16 at 02:58
  • Still an issue with VS 2015 Upd3 Nuget 3.5, packages are checked in and I have no \MySolution\.NuGet\NuGet.config – Mikee Jan 15 '17 at 14:59
  • 1
    @Mikee Unless I am misunderstanding you, the lack of the nuget.config file (and hence the `disableSourceControlIntegration` directive) is why the packages are being checked in. – nick_w Jan 16 '17 at 19:41
  • @nick_w Am I wrong in thinking that by default now VS2015\NuGet should be configured to not check in packages? ....it's been quite sometime since I created a new solution under source control. – Mikee Jan 16 '17 at 19:59
  • @Mikee I don't believe that a NuGet.config file is added to the solution by default, meaning that packages are getting checked in. If you want to you could disable the package checkin at your user profile level so that it gets applied to any solution. Like you, I am surprised that a more sensible default has not yet been arrived at given how undesirable it is to check packages in. – nick_w Jan 16 '17 at 21:07
5

In your %AppData%\NuGet\NuGet.Config file, add the following just before the </configuration> XML tag...

<config>
  <add key="repositoryPath" value="C:\NuGetPackages" />
</config>
<solution>
  <add key="disableSourceControlIntegration" value="true" />
</solution>

...you can specify any path you want - the important thing is putting it OUTSIDE your TFS workspace!

Now you never have to worry about that stuff again. Your solution folder will not contain any packages anymore; all solutions will default to using your custom packages location instead.

NOTE - This works is on a per-user basis.

Until now, I've been doing the same in a one-config-per-solution (\.nuget\NuGet.Config) manner. Thanks to @dsghi for the insight!

Make sure your solution folder does not contain a .nuget folder (old way of doing things). Even if the folder is NOT included in the solution and only in the file system, it will override everything!

Riegardt Steyn
  • 5,431
  • 2
  • 34
  • 49
  • This worked but you really have 2 answers going on here. I only want to `disableSourceControlIntegration` not also pick a new location for the `repositoryPath`. – Rick Glos Jan 06 '16 at 20:18
  • The reason this works is most likely because you have updated your version of the NuGet VS 2015 Extension. In version 3.1 the `disableSourceControlIntegration` setting didn't work no matter where your config file was. – nick_w Jan 06 '16 at 22:53
  • Hmm, that's strange. I've been doing this since VS2013 – Riegardt Steyn Jan 07 '16 at 11:19
  • 2
    Me too. What I mean is that 3.1 broke support for that setting - it worked fine before and after that. – nick_w Jan 07 '16 at 23:27
0

I have the same problem and I haven't found a real solution yet.

The only workaround I've found so far is:

  • Right click the packages folder in "Team Explorer - Pending Changes" and select "undo".
Drol
  • 189
  • 1
  • 6
  • The workaround really just step 1. "Undo pending changes" doesn't delete files, and you don't have to check in right away. While, it's good that there is a reasonable workaround, perhaps is presence is also the curse that has kept this bug from getting any love for so long. – Edward Brey Aug 11 '15 at 12:03
  • Yeah you are correct. I was overthinking the problem. – Drol Aug 11 '15 at 13:56