How to: Create a C# Test Project 

The following sections explain how to create and run the C# code example to automate Visual SourceSafe through the use of the IVSSDatabase interface that represents a Visual SourceSafe database

Create a C# Test Project

To create a test project in C# do the following:

  1. Create a new SourceSafe database at c:\VSSTestDB.

    For details on how to create a new database, see How to: Log In to Visual SourceSafe.

  2. Start Visual Studio and, from the Start page, choose New Project.

  3. Select Visual C# Projects from the tree view on the left side of the screen.

  4. Select Console Application as the project template.

  5. Set the name of the application to IVSSTest and click OK to create the project.

  6. Highlight the file called Class1.cs in Solution Explorer and rename it to PName.cs. Completely delete the code inserted by Visual Studio into this file.

  7. To use the Primary Interop Assembly for the SSAPI.DLL COM component, select References under IVSSTest project; use right mouse button and then select Add Reference. Make sure that the .NET tab is selected, and use Select button to select IVSS Microsoft.VisualStudio.SourceSafe.Interop.dll Primary Interop Assembly. This will add the component to the Selected Components list.

  8. Click OK.

Add Sample Code

The following example demonstrates how to use the Name property of the IVSSItem interface.

  • Paste the code below into PName.cs.

    using System;
    using Microsoft.VisualStudio.SourceSafe.Interop;
    
    public class IVSSTest
    {
        public static void Main()
        {
            // Create a VSSDatabase object.
            VSSDatabase vssDatabase = new VSSDatabase();
    
            // Open a VSS database using network name for automatic user login.
            vssDatabase.Open(@"C:\VSSTestDB\srcsafe.ini", Environment.UserName, ""); 
    
            // vssFolder represents a SourceSafe project "TestFolder".
            IVSSItem vssFolder = vssDatabase.get_VSSItem("$/TestFolder", false);
    
            Console.WriteLine("'{0}' folder name is '{1}'", vssFolder.Spec, vssFolder.Name);
        }
    }
    

Test the Application

To test the application do the following:

  • Press Control+F5 to build and run your application.

    The application output:'$/TestFolder' folder name is 'TestFolder.

See Also

Tasks

How to: Create a Visual Basic Test Project
How to: Log In to Visual SourceSafe

Other Resources

Driving a SourceSafe Database
Trapping SourceSafe Events