Click here to Skip to main content
15,886,362 members
Articles / Desktop Programming / MFC
Article

VSSXML: dump Visual SourceSafe project in XML format

Rate me:
Please Sign up or sign in to vote.
3.82/5 (11 votes)
11 Dec 20025 min read 79.8K   1.1K   26   12
Using VSS automation to dump information of VSS database.

Introduction

Many persons and teams use Visual SourceSafe (VSS) together with Visual C++. Visual SourceSafe is easy to use, but it is far from convenient. Many third-party products provide some kind of automatic features to VSS. If you want to do your own automatic tasks, such as auto-build, auto-backup, auto-notification, the tree structure of projects and other information are needed. VSSXML uses VSS Automation interface to dump out the projects information in a VSS database.

I just read the documents and put the code together. But it is good to provide a full example of VSS automation instead of only pieces of code.

Background

Some third-party products that do some automatic tasks with VSS use the add-in mode. That's to say, an add-in DLL is loaded by VSS and be notified when some events occur. Other products use a timer based query mode, they query the VSS database at specific time intervals to see if there are any changes.

VSSXML queries the VSS database and outputs the version information of the project as well as its subitems in XML format, which can be used in other tasks. And, you may modify the source code to do some tasks such as auto-download.

The following products also use VSS automation interface:

Usage

VSSXML is a console program rather than a GUI tool. It provides a few arguments to tell the program which project to dump.

The parameter --database contains the full path filename of the initialization file of the VSS database. If the path or file name contains any space, a pair of quotation marks(") may be used.

The parameter --item contains the full path of the item you are interested in, if it is omitted, the root "$/" is used as default.

The parameter --output contains the output XML filename, if it is omitted, the XML file will be dumped to standard output device stdout.

The parameters --user and --password are needed when the VSS database needs a login to connect to the database. The default user is guest and the default password is blank.

You may use the format argument=value or argument value for each parameter that needs a value.

See the following examples:

  • vssxml --database="C:\Program Files\Microsoft Visual Studio\Common\VSS\srcsafe.ini" --output c:\temp\test.xml --item="$/My Project/VSSXML"

    This command dumps the branch $/My Project/VSSXML of local VSS database to local file c:\temp\test.xml.

  • vssxml --database="C:\Program Files\Microsoft Visual Studio\Common\VSS\srcsafe.ini" --output c:\temp\test.xml --item="$/My Project/VSSXML" --user=admin --password mypass

    This command dumps the same branch using login - admin and password - "mypass".

Using the code

The main code is short and straightforward. There are no classes, only three functions to dump the VSS database and several functions that deal with the command arguments. Function DumpProject opens a given project in a VSS database and calls DumpItem to dump all the projects and files in a recursive way. Function DumpVersion dumps all the versions of a special file. Only the versions of files are dumped in XML format. The versions of a project contains all the information of its subitems.

You may see the Reference and Further Reading section to get background information about IVSSDatabase, IVSSItems, IVSSItem, IVSSVersions, IVSSVersion and other VSS interfaces.

Only a few lines of source are not straightforward like other parts of the program. The following code uses the _NewEnum and Next methods of IVSSVersions to find all the subitems of IVSSVersions, see the Points of Interest section for details.

IVSSVersions* pVersions = NULL;
pItem->get_Versions(0, &pVersions);

IUnknown* pEnumerator = NULL;
pVersions->_NewEnum(&pEnumerator);

if (pEnumerator)
{
    IEnumVARIANT* pVariant = NULL;
    pEnumerator->QueryInterface(IID_IEnumVARIANT, (void **) &pVariant);
    pEnumerator->Release();
    
    HRESULT h = pVariant->Next((unsigned long) 1, &v, &actual);
    
    while (h==0)
    {
        IVSSVersion* pVersion = NULL;
        v.pdispVal->QueryInterface(IID_IVSSVersion, (void **) &pVersion);
        
        DumpVersion(file, indent+2, pVersion);
        
        h = pVariant->Next((unsigned long) 1, &v, &actual);
    }
}

Points of Interest

The most interesting thing about VSS automation is from Microsoft's document, saying that, "The Count property and Item method are not implemented in this collection (IVSSVersions). The only way to use this collection is to call the _NewEnum method (C++), or use a for each loop (VB)." The Count and Item are implemented in other VSS interfaces.

Because of this, if only the type library ssapi.dll is imported, it is hard to visit the subitems of class IVSSVersions. File ssauto.h (from Microsoft) contains the declaration of the VSS interfaces.

Need Your Advice

I am now thinking about writing a program to automatically download new versions of source file from VSS database and build them using nmake. I am working on a large project with many other programmers and it costs too much time to build a new version. The feather of automatic download and build to see if there are any compile errors, is needed. The programmer who checked in the files that cause the compile errors will be notified using email.

I have not decided that whether to use the .dsp or .mak files of the project from VSS or create a .mak file by the program. In the first approach, we need the programmers update the .dsp or .mak files immediately after they add or delete files from project. In the second approach, we may encounter problems in creating the .mak files.

Known issues

The program is only intended to be used with Microsoft Visual SourceSafe 6.0. It is tested on Windows 2000. The program does not handle OLE errors, the VSS client should be properly installed.

It seems that the program is a little slower than VSS' client, Visual SourceSafe Explorer.

I do not know how to figure out the users of the database.

Reference and Further Reading

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here


Written By
Web Developer
United States United States
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralHi, I am quite interested in your topic Pin
xiongzhend21-Sep-06 22:55
xiongzhend21-Sep-06 22:55 
QuestionWhy not use CruiseControl.NET? Pin
Andreas Kroll6-Sep-05 22:19
Andreas Kroll6-Sep-05 22:19 
GeneralVSS Fetch (Is Anyone There??) Pin
daveshawley12-Mar-03 17:58
daveshawley12-Mar-03 17:58 
Ning,

Nice tool. I've been working on a VSS build automation
tool that slurps in a XML file that describes the components
to fetch from VSS and build. I ran into a problem recently
that I was wondering if you have ever seen -- when I invoke
IVSSItem::Get on a label item it doesn't reliably fetch all
of the sub projects. It seems to differ from one machine
to the next... I'm really stumped here (otherwise I wouldn't
be asking random people for help =-)

I can send you a very short example that the fetch fails in
if you are interested.

Dave Shawley
Senior Software Architect
SeaChange International

GeneralUtility crashes Pin
markgg28-Feb-03 3:49
markgg28-Feb-03 3:49 
GeneralRe: Utility crashes Pin
S.Uemura9-Jul-03 6:24
S.Uemura9-Jul-03 6:24 
GeneralRe: Utility crashes Pin
Ning Cao2-Apr-05 19:04
Ning Cao2-Apr-05 19:04 
GeneralVisual SourceSafe Automation Pin
rmh5-Jan-03 8:51
rmh5-Jan-03 8:51 
Generalmissing zip files!! Pin
felis66611-Dec-02 23:29
felis66611-Dec-02 23:29 
GeneralRe: missing zip files!! Pin
Ning Cao12-Dec-02 1:31
Ning Cao12-Dec-02 1:31 
GeneralRe: missing zip files!! - Pin
at_breakingpoint24-Feb-03 6:54
at_breakingpoint24-Feb-03 6:54 
GeneralRe: missing zip files!! - Pin
Ning Cao24-Feb-03 17:42
Ning Cao24-Feb-03 17:42 
GeneralRe: missing zip files!! - Pin
GE - NBGYF11-Jun-04 16:01
GE - NBGYF11-Jun-04 16:01 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.