A common practice when using Subversion is to ignore build output files such as DLLs and EXEs. However, there are times when you want to include these sorts of files, such as when you add a new NuGet package to your project. There is a poorly-documented feature in Subversion that allows you to un-ignore files by using negative ignore patterns. Here’s how you can take advantage of that.
The Scenario
Let’s say you have a solution that references one or more NuGet packages. Today, the most common practice is to include NuGet packages in your source-control system (though that may change soon). Unfortunately, most NuGet packages contain files that are commonly excluded from source control, such as EXEs, DLLs, and HTML files. When adding a new NuGet package, you must either disable your global ignore patterns before performing an ‘svn add’, or you must manually ‘svn add’ each file that was ignored. The same is true even when you upgrade a NuGet package, as the new version of the package will be placed in a new folder. Wouldn’t it be great if running an ‘svn add’ on your packages folder always added all new files, even if they matched one of your global ignore filters?
Hello Negative Patterns!
One of the things I love about git is that it’s very easy to override ignore settings on a per-directory basis. I didn’t think Subversion had such a capability, but it turns out I was wrong! It’s not really documented anywhere that I could find, but the ‘svn:ignore’ property does indeed support negative patterns, and these can override both ignore patterns from higher level ‘svn:ignore’ properties as well as your global ignore setting. You can read more about this over at ThoughtSpark.
The following procedure assumes you have TortoiseSVN installed, but it can be easily adapted and performed using the command-line SVN tools.
To override your SVN ignore settings and include all files in your solution’s ‘packages’ folder, right-click the folder and choose “TortoiseSVN –> Properties”. Click the “New” button to add a new ‘svn:ignore’ property, and use the following pattern: [!*]
Click ‘Ok’ to add the property, then ‘Ok’ again to close the Properties dialog. Now when you run an ‘svn add’ command on your packages folder, all of the uncommitted files under the directory will be shown!
And there you have it! No more manually adding files to Subversion whenever you add or upgrade a package!