5

I'm trying to follow the no-commit strategy in keeping assemblies out of TFS while using NuGet. I'd like the projects to auto-restore dependencies and not add pending changes to TFS.

I've read a few ways to do this; one being using .tfignore, which will be a pain with the number of projects we have. We could cloak the folder in TFS, but we would need to add the packages folder for every project in order to cloak it. The last way, is to configure NuGet via NuGet.config using disableSourceControlIntegration which will keep the NugetClient from adding the packages to the project or solution.

**This is the configuration XML I'm using:

<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>

If I place it in my {SolutionDir}.nuget folder it works for that solution. I'm trying to place it in my %AppData%\nuget folder so that it is applied to all solutions but package restore is still causing TFS to add my packages folder contents.

I'm using Visual Studio 2013, NuGet 2.8.6 and TFS from VSOnline.**

Daniel Mann
  • 57,011
  • 13
  • 100
  • 120

3 Answers3

10

I dont think there is a way to put this key in the root location, looks like Nuget only honors the key when it is specified in the {SolutionDir}.nuget folder. The Nuget document clearly mentions that this key works at solution level and need to added to the {SolutionDir}.nuget folder.

Source Control Integration "disableSourceControlIntegration" under section "solution" allows you to disable source control integration for the "Packages" folder. This key works at the solution level and hence need to be added in a NuGet.config file in the "$(SolutionDir).nuget directory". The default value for this key is true.

EDIT & UPDATE : thanks to @TonyStewart871 for finding this information. I haven't tested this in Version 3.2 nor could find the official documentation.

But as per this GITHUB LINK Comments Section, from NuGet version 3.2 it is possible to add the key "disableSourceControlIntegration" at the user level for all solution's in the %appdata%\nuget\nuget.config file instead of adding at the individual solution level. Please find below the comment from deepakaravindr:

"You can add the setting not just to the solution level nuget.config, but also to your nuget.config at %appdata%\nuget. That works too! Just that it will get applied to every solution that you open on that machine. Remember to add the following section as a child to < configuration > section. And, note that the setting should always be under the < solution > section for it to work"

<solution>
    <add key="disableSourceControlIntegration" value="true" />
</solution>

NUGET Documentation

Isaiah4110
  • 9,855
  • 1
  • 40
  • 56
  • 1
    Based on the documentation, I believe this to be correct for the version I stated. It seems like version 3.2 may have added support for this feature at the user level, however I can't find official documentation. Others have listed this functionality in a comment here: [link]http://stackoverflow.com/questions/31887010/how-to-keep-vs2015-nuget-from-adding-packages-to-tfs and here: [link]https://github.com/NuGet/Home/issues/980 in the contributor's(deepakaravindr) comments. – TonyStewart871 Nov 12 '15 at 23:41
  • Thank you for digging and finding that, I will update the answer! – Isaiah4110 Nov 13 '15 at 04:33
1

There is a DisableSourceControlIntegration-TFS NuGet package that will add the {SolutionDir}.nuget folder and config files to the solution, as well as a .tfignore file for the NuGet packages folder. It's even easier than adding a single config file by hand. You can find it here: https://www.nuget.org/packages/DisableSourceControlIntegration-TFS.

Anne Thompson
  • 117
  • 1
  • 10
0

It is correct this strategy of allow exclusion of NuGet Packages folder relatively to a single TFS project, because has sense to exclude nuget packages only if you needs to have access on a common project repository from several developers.

And so, if anyone needs to replicate solution's structure on his local machine restoring first time only NuGet packages (and so its content (libraries)), can do it without having any problems related to compatibility libraries and so on..
Every time NuGet restore libraries in Packages folder and solution compiles well.

While, if you only should configure NuGet behaviuor, others developer should have so too and therefore it should miss the convenience about this configuration policy: anyone should replicate this configuration rule everytime on his local machine..

Instead, storing this rule in tfs with its solution allows to everyone to inherits this rule.

Alternatevely, if one wants to work on a project alone, he can avoid if he wants to configure NuGet for don't commit its "Packages" folder content, and so the strategy of store this particular NuGet rule in TFS it is a good choice.

Ciro Corvino
  • 2,038
  • 5
  • 20
  • 33