Click here to Skip to main content
13,353,706 members (56,461 online)
Click here to Skip to main content
Add your own
alternative version


43 bookmarked
Posted 28 Feb 2006

MSBuild Task Tutorial: Label SourceSafe Project

, 28 Feb 2006
Rate this:
Please Sign up or sign in to vote.
Create your own MSBuild Task to label SourceSafe projects


While attempting to automate my build process using MSBuild, I have been unable to find a MSBuild Task to label projects in Visual SourceSafe. So, I decided to roll my own using C#. Since you are reading this, you are probably aware that MSBuild is the new build platform from Microsoft. If you are unfamiliar with MSBuild, check out the list of resources at the bottom of this page for an introduction.

Tools Involved

During the course of this tutorial, I use the following tools:

  • Visual Studio 2005
  • Microsoft Visual Studio 2005 Web Deployment Project
  • Microsoft Visual SourceSafe 6.0
  • MSBuild

Step 1: Create your MSBuild Task Project

Start by opening Visual Studio 2005 and creating a class library project. Name it something clever, like VSSTasks.

Sample image

Step 2: Add the Label Project Class

Create a new class file and name it LabelProject.cs.

Sample image

Add the following code to the LabelProject.cs file:

using Microsoft.Build.Framework;
using SourceSafeTypeLib;

namespace VSSTask
    public class LabelProject : ITask

#region Properties
        private IBuildEngine engine;
        public IBuildEngine BuildEngine
            get { return engine; }
            set { engine = value; }

        private ITaskHost host;
        public ITaskHost HostObject
            get { return host; }
            set { host = value; }

        private string vssINIPath;
        public string VSSINIPath
            get { return vssINIPath; }
            set { vssINIPath = value; }

        private string vssUserName;
        public string VSSUserName
            get { return vssUserName; }
            set { vssUserName = value; }

        private string vssPassword;
        public string VSSPassword
            get { return vssPassword; }
            set { vssPassword = value; }

        private string vssProjectPath;
        public string VSSProjectPath
            get { return vssProjectPath; }
            set { vssProjectPath = value; }

        private string vssLabelText = "";
        /// <span class="code-SummaryComment"><SUMMARY></span>
        /// Provide a string up to 31 characters long.
        /// <span class="code-SummaryComment"></SUMMARY></span>
        public string VSSLabelText
            get { return vssLabelText; }
                // only get the first 31 characters
                if (value.Length > 0)
                    vssLabelText = value.Substring(0, 31);

        private string vssCommentText =
           "Label generated automatically by MSBuild VSSTask";
        public string VSSCommentText
            get { return vssCommentText; }
            set { vssCommentText = value; }

#endregion Properties

        public bool Execute()
            // Create SourceSafe ActiveX object
            SourceSafeTypeLib.VSSDatabase sourceSafeObject =
                   new SourceSafeTypeLib.VSSDatabase();

            // Open a connection to the SourceSafe database=
            // using the srcsafe.ini file and a  valid
            // userid/password combination.
            sourceSafeObject.Open(vssINIPath, vssUserName, vssPassword);

            // Get reference to project we wish to label
            VSSItem vssProjectItem =
               sourceSafeObject.get_VSSItem(vssProjectPath, false);

            vssProjectItem.Label(vssLabelText, vssCommentText);

            string message = "VSS Label Successfully Set to " + vssLabelText;
            BuildMessageEventArgs args = new BuildMessageEventArgs(
                message, string.Empty, "SetVSSLabel", MessageImportance.Normal);

            sourceSafeObject = null;
            vssProjectItem = null;

            return true;

Step 3: Add Necessary References

You will need to add two references to your VSSTasks project. First, add a reference to the Microsoft.Build.Framework. It should be located under the .NET tab on the Add Reference screen.

Sample image

Adding the reference to the Microsoft SourceSafe 6.0 Type Library (SSAPI.DLL), which is installed along with SourceSafe, is slightly more complicated. I assume that you have a local copy of Visual SourceSafe installed. You will need to browse to the SSAPI.DLL file via the Add Reference screen.

In my case, the path to the SSAPI.DLL is:

C:\Program Files\Microsoft Visual Studio\VSS\win32\SSAPI.DLL 

Step 4: Implementation

Compile your new VSSTasks project. Atta boy!

I use Microsoft Visual Studio 2005 Web Deployment Project to create my MSBuild project files. I highly recommend it, if you are automating the build process of an ASP.NET project. Check out the list of resources at the bottom of this page for examples of how to get started with the Web Deployment Project. For the sake of this article, I will assume that you have already added a Web Deployment Project to your own ASP.NET project in Visual Studio 2005.
Inside of your Web deployment project file (*.wdproj), you will add a reference to your newly created LabelProject task.

<USINGTASK TaskName="VSSTask.LabelProject"

           AssemblyFile="C:\dev\VSSTasks\VSSTasks\bin\Debug\VSSTasks.dll" />

Then add the following PropertyGroup element:

   <VSSINIPATH>C:\Program Files\Microsoft Visual Studio\VSS\srcsafe.ini</VSSINIPATH>
   <VSSCOMMENTTEXT>Label generated by MSBuild using LableProject task.</VSSCOMMENTTEXT>

Finally, add the task you just created to the After Build target element:

<Target Name="AfterBuild">
   <LabelProject VSSINIPath="$(VSSINIPath)"





                 VSSCommentText="$(VSSCommentText)" />

Step 5: It's Run Time, Baby!

Build your Web Deployment project either via the Visual Studio 2005 IDE, or you can do so using MSBuild and the command line.


C:\MyProjects\MyWeb>msbuild MyWeb.sln /p:Configuration=Debug

The output from the build process should include the following text:

VSS Label Successfully Set to Testing LabelProject Class

Step 6: Verify that VSS Project was Labeled

Open Visual SourceSafe. Right click your project and select Properties. Under the General tab, you should see the Last Label text, followed by the text you specified in the VSSLabelText property in your Web Deployment Project file.

Sample image

Congratulations, you have just labeled a Visual SourceSafe project using a MSBuild task, created with C# and Visual Studio 2005.


Don't stop now. You are only getting started. Why not create a task to get the latest version of your project from SourceSafe?


You should now see both the Microsoft.Build.Framework and the SourceSafeTypeLib in your list of references.

Sample image


  • 28th February, 2006: Initial post


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author
Software Developer (Senior)
United States United States
No Biography provided

You may also be interested in...

Comments and Discussions

Questioncan i make exe using MSBuild in my desktop application? Pin
Irfan Kothari3-Nov-06 21:21
memberIrfan Kothari3-Nov-06 21:21 
QuestionSobaka Pin
Yustos28-Aug-06 0:45
memberYustos28-Aug-06 0:45 
AnswerRe: Sobaka Pin
tod1d.net28-Aug-06 5:19
membertod1d.net28-Aug-06 5:19 
Generalssapi Get with label Pin
NigelAston24-May-06 6:10
memberNigelAston24-May-06 6:10 
GeneralBuild Tasks Pin
Shaun Wilde6-Mar-06 20:35
memberShaun Wilde6-Mar-06 20:35 
There is a whole collection of build tasks created by an internal team at Microsoft UK that is used for automated builds which you may find of interest.[^]

There are 10 sorts of people in this world. Those who understand binary and those that don't.

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.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web04 | 2.8.180111.1 | Last Updated 28 Feb 2006
Article Copyright 2006 by
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid