Keyword Expansion in Visual SourceSafe

Keyword expansion is a cool feature that automagically plants metadata from an external
source in a file–typically between two pre-defined characters or strings–when some
event occurs. In SourceSafe, there are twelve
standard keywords
 to which various types of metadata are appended when a
file in which they reside is checked in[1].

The online documentation provides a pretty good
overview of SourceSafe keyword expansion
and some interesting tips and tricks to
help you maximize the utility of the feature. It also explains how
to enable keyword expansion in VSS
. Please note that there is a minor documentation
bug in this
.  The code that appears below “If no keyword comments are specified,
the following comments are assumed:
” should begin with “[Keyword Comments]”.
More details in the FAQs below.

IMO, the most useful Visual SourceSafe keyword is $history: $. In conjunction
with SourceSafe’s
Shadow Folder feature
, the $history:  $ keyword is really nifty because
it allows you to know when the file was last edited and by whom even when you’re not
accessing it from the database. $history: $ tells SourceSafe to add something
like the following to a file when you check it in:

‘$History: Form1.vb $

‘*****************  Version 24  *****************
‘User: Guest        Date: 10/13/03  
Time: 12:49p
‘Updated in

FAQs and Gotchas:
Q: How do you turn on VSS keyword expansion?
A: See how
to enable keyword expansion in VSS

Q: I enabled keyword expansion but it is still not working. Why?
A: Before using this feature, you must close and all database clients that are connected
to the database.

Keywords are case-sensitive, so confirm that they are properly capitalized.

Keyword expansion is disabled by default. Use VSS Admin to make sure that the feature
is enabled for files of the type to which you have added keywords (eg, “*.cs”).

Q: How can I automatically add comments to keyword expanded text in my source files
(*.vb, *.cs, etc)?
A: Insert the following into either your personal Ss.INI file or into the
database-wide Srcsafe.INI:
[Keyword Comments]
*.cs = “//”
*.vb = “‘”

[1]Q: Can I create custom VSS keywords, such as $assembly_version: $ ?
A: No. But that would be a JAW DROPPING extensibility feature, wouldn’t it?

Gotcha #1: Keyword Expansion can adversely affect performance.
Gotcha #2: Don’t enable keyword expansion for binary
files.  Just don’t.

Additional Resources:

Ce message est fourni en l état, sans garantie d aucune
sorte, et ne vous confère aucun droit. Vous assumez tous les risques liés à son utilisation.This
posting is provided “AS IS” with no warranties, and confers no rights.

Comments (7)

  1. AsbjornM says:

    But from time to time I observe that the expansion does’nt work well always when using VS.NET, i.e. the $Archive tag will only expand when it’s empty, so when I rename a file, or copy (god forbid) it to another project it doesn’t change, I have to empty it, and check in to get it expanded correctly?
    $revision seems okay, but there is possible some that are alway expanded and some not?

  2. AsbjornM says:

    BTW, I found this one übercool:
    Private m_version As String = "$Header: $"
    Very useful to determine the correct revision for that class/module when things go bad..

  3. Chris Kennedy says:

    If your keyword expansion seems not to be working, check the codepage of the file. If it isn’t in the windows standard codepage, then it doesn’t work. I just changed about 50 database scripts from unicode. Keyword expansion works now…

  4. Keyword expansion on SQL files is tricky. If you put them at the top the whole thing gets stripped out. Apparently you have to put them AFTER the CREATE/ALTER statements for them to be kept but that ADVERSELY affects readability and appearance.

    Perhaps putting them at the end but the idea is that that is the first thing you look at.