Visual SourceSafe automation
I've been busy this week with quite an interesting little
project regarding VSTO and SourceSafe and had the opportunity (misfortune?), working
with the SourceSafe API (ssapi.ddl).
The API is pretty straightforward not much to it, I've included some code below,
which demonstrates how to do a simple get latest.
The same approach can be used (minus the get method) to build yourself a little
treeview, passing the needed node along with the recursion, generating a nested
structure.
using SourceSafeTypeLib;
using System.IO;
class Program
{
static VSSDatabaseClass database = new VSSDatabaseClass();
private static void getLatest(string Spec, string Local)
{
VSSItem Item = database.get_VSSItem(Spec, false);
Item.Get(ref Local, 0);
foreach (VSSItem ChildItem in Item.get_Items(false))
{
if (ChildItem.Type == 0)
{
getLatest(ChildItem.Spec, Path.Combine(Local, ChildItem.Name));
}
}
}
static void Main(string[] args)
{
database.Open(@"\\sourcesafe\sources\srcsafe.ini", "username", "password");
getLatest("$/SomeProject", @"c:\SomeProject\");
}
}
What we've got here, is a recursive method, retrieving all files within a specified
repository, the get method will create the needed folders on your local machine, and
fetch all files within that folder (excluding folders hence the need for recursion)
We can pass a number of flags (VSSFlags enumerator) to this method to alter its behavior,
for whatever our needs may be.
Looking a bit further, you'll notice a number of abstract classes, interfaces an enumerators
(imported from the ssapi assembly via interop functionality in .net) - which provide wrappers
to the API.
The one you'd be interested in the most is VSSDatabaseClass - which is our main entry point,
from there you can build the rest of your needed functionality.
Posted by - Christoff Truter
Date - 2008-07-18 09:25:51
Post comment