Sourcesafe Automation Tips

I am currently playing with the Visual Sourcesafe Automation for implementation in one of my projects. I was trying to traverse the files of a specific project (aka folder) and the code in Visual Basic.NET works like this:


Dim vssDB As IVSSDatabase = New VSSDatabase
vssDB.Open("srcsafe.ini location", "username", "password")
Dim sfolder As VSSItem
sfolder = vssDB.VSSItem("$/MyProject").Items(True).Item(1)

Dim xItem As VSSItem

For Each xItem In sfolder.Items(False)
System.Diagnostics.Debug.Print(xItem.Name & " - " & xItem.VersionNumber)
'xItem.Checkout()
'xItem.Checkin()
'xItem.Get("c:\\temp1")
Next

If I want to perform some of the operations (such as check in/out), I just have to modify the lines in the for each loop to work. Since I am a C# developer, I translated the same code and it appears like this:

IVSSDatabase vssDB = new VSSDatabase();
vssDB.Open("srcsafe.ini location", "username", "password");
VSSItem sfolder;

sfolder = vssDB.VSSItem("$/MyProject").Items(true).Item(1);

VSSItem xItem;

foreach ( xItem in sfolder.Items(false)) {
System.Diagnostics.Debug.Print(xItem.Name + " - " + xItem.VersionNumber);
//xItem.Checkout();
//xItem.Checkin();
//xItem.Get("c:\\temp1");
}

What keeps me wondering is that the code for VB works while the one for C# had errors. Specifically on line 5, it triggers an error that the VSSItem is not supported by the language. I made a workaround on the structure and the working version is this:

IVSSDatabase vssDB = new VSSDatabase();
vssDB.Open("srcsafe.ini location", "username", "password");
VSSItem sfolder;

sfolder = (VSSItem)vssDB.get_VSSItem("$/MyWebsite", false);

foreach ( VSSItem xItem in sfolder.get_Items(false)) {
string outputdisplay = xItem.Name + " - " + xItem.VersionNumber + "<br />";
Response.Write(outputdisplay);
//xItem.Checkout("comments_here", "checkout_location", 0);
//xItem.Checkin("comments_here", "checkout_location", 0);
}

Since C# doesn’t accept optional parameters, you need to fill-in for the parameters. I hope this one helps and makes sense for those who are working on Sourcesafe Automation. 🙂

Advertisements

1 Response to “Sourcesafe Automation Tips”



  1. 1 Sourcesafe Automation Bug « BuLOnG Trackback on April 14, 2008 at 1:26 pm

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s




Blog Stats

  • 3,922 hits
October 2007
S M T W T F S
« Sep   Nov »
 123456
78910111213
14151617181920
21222324252627
28293031  

%d bloggers like this: