How to ignore files/directories in TFS for avoiding them to go to central source repository?
tfs
Solution
For VS2015 and VS2017
Works with TFS (on-prem) or VSO (Visual Studio Online - the Azure-hosted offering)
The NuGet documentation provides instructions on how to accomplish this and I just followed them successfully for Visual Studio 2015 & Visual Studio 2017 against VSTS (Azure-hosted TFS). Everything is fully updated as of Nov 2016 Aug 2018.
I recommend you follow NuGet's instructions but just to recap what I did:
- Make sure your `packages` folder is not committed to TFS. If it is, get it out of there.
- Everything else we create below goes into the same folder that your `.sln` file exists in unless otherwise specified (NuGet's instructions aren't completely clear on this).
- Create a `.nuget` folder. You can use Windows Explorer to name it `.nuget.` for it to successfully save as `.nuget` (it automatically removes the last period) but directly trying to name it `.nuget` may not work (you may get an error or it may change the name, depending on your version of Windows). Or name the directory nuget, and open the parent directory in command line prompt. type. ren nuget .nuget
- Inside of that folder, create a `NuGet.config` file and add the following contents and save it:
NuGet.config:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<solution>
<add key="disableSourceControlIntegration" value="true" />
</solution>
</configuration>
- Go back in your `.sln`'s folder and create a new text file and name it `.tfignore` (if using Windows Explorer, use the same trick as above and name it `.tfignore.`)
- Put the following content into that file:
.tfignore:
# Ignore the NuGet packages folder in the root of the repository.
# If needed, prefix 'packages' with additional folder names if it's
# not in the same folder as .tfignore.
packages
# include package target files which may be required for msbuild,
# again prefixing the folder name as needed.
!packages/*.targets
- Save all of this, commit it to TFS, then close & re-open Visual Studio and the Team Explorer should no longer identify the packages folder as a pending check-in.
- Copy/pasted via Windows Explorer the `.tfignore` file and `.nuget` folder to all of my various solutions and committed them and I no longer have the `packages` folder trying to sneak into my source control repo!
Further Customization
While not mine, I have found this `.tfignore` template by sirkirby to be handy. The example in my answer covers the Nuget `packages` folder but this template includes some other things as well as provides additional examples that can be useful if you wish to customize this further.
Problem
Is it possible to set up files/folders to ignore on a per-project basis in TFS source control? For example, I've a website with an assets folder that I do not want to go in to source control. These assets are maintained by a separate system. Also, I don't want to put several gigabytes of assets into source control, but I need a couple of samples on my dev machine, but I don't want to check those in either. If I'm working on this website while bound to source control and I refresh the tree, these files will automatically get added again I want to prevent this from happening.