SVN Externals

15.10.2009 19:33Comments
Improving your source code structure with SVN Externals Svn "externals" is an SVN property of folders, which you can use to set external links. By doing this, you avoid having to copy the same folder in multiple locations, and you get to make changes only once and in only one place. There are two ways to set an SVN property, through the command line or (if your svn client supports it) through the UI. In this case I will show you how to set the properties through the UI of the TortoiseSVN (my favorite SVN client). First of all, you have to decide the folder of reference. Inside this reference folder you will have the external links. The syntax is as follows: pathRelativeToYourFolder http://svnpathtoexternallink So, first you put the path relative to the folder you right-clicked, and then the SVN url to the “external link” folder. As simple as that you can add external links to all your project folders. Now let’s try to improve our source code structure using externals. If you followed my previous post about code structure, or if you have a similar structure you should have something like this: SVN basic structure Many of your projects will most  likely going to have a lot of the “lib” folder in common (for more information about the lib folder see this), such as nunit, nant, enterprise library, asp .net ajax toolkit, etc. So it makes sense to take the lib folder to a totally different path, outside of every project, and add it as external links to each project that may need it. So all you need to do is create a lib folder outside the scope of your project, put all the lib stuff inside, and then go to the trunk folder, right click, go to TortoiseSVN -> Properties, and finally add an svn:externals property with the following text: lib http://yoursvn/path-to-the-lib-folder From now on you can keep your lib folder always up-to-date in all of your projects at the same time! Notice however, that changes to the lib folder have to be done in the http://yoursvn/path-to-the-lib-folder repository and not inside your trunk’s lib folder. Another thing to take into account is that if the lib folder grows too big, you can always do a checkout excluding the “externals”. In this post we have improved the structure of our repository by moving the lib folder to a common place for all our projects, adding an external link using the svn:externals property.

comments powered by Disqus