Using Visual SourceSafe 2005 with Visual Studio 2005


Introduction

Visual SourceSafe 2005 (VSS) is a source or version control system implemented as a client/server application creating a virtual library of files which acts as storage file system. This virtual library can be accessed through the VSS client tools (VSS windows client, VSS command-line tool) and plug-in embedded in development environment such as the VSS plug-in for Visual Studio.NET. In this article, I will show how two developers can work together in a Visual Studio.NET project to cooperatively develop a solution using the LAN plug-in for Visual Studio.NET integrated with this IDE.

Using Visual Sourcesafe

In order to illustrate the concepts and techniques to use Visual SourceSafe integrated with Visual Studio.NET, we're going to consider the following scenario in which two developers, with the VSS tools installed on two development machines (development1, development2), have to cooperatively develop a solution in Visual Studio.NET 2005 and for the source control they use Visual SourceSafe 2005 LAN plug-in to connect to a development server (named developmentserver).

In order to create the VSS database in the developmentserver, you must go to the machine developmentserver.

Open the Visual SourceSafe Administrator application, go to the File | New Database menu in order to launch the Add SourceSafe Database Wizard, and then click on the Next button. In the New Database Location page, browse to the location where the VSS database will reside, and click on the Next button (see Figure 1).

Figure 1

In the Database Connection Name, you have to type a name for the database (see Figure 2).

Figure 2

In the Team Version Control Model page, select the default settings, and click on the Next button to finish with the wizard (see Figure 3).

Figure 3

After that, the VSS database is created, and you can manage this database using the VSS Administrator. For example, let's add a two VSS user to the database, by going to the Users |Add User menu and typing data to the required fields (see Figure 4 and Figure 5). This enables VSS to handle its own authentication process rather than integrating with Windows authentication through file access and NTFS permissions.

Figure 4

Figure 5

Now in the developmentserver machine, we have to define the solution to be developed and its structure, and then upload this solution to the VSS database.

In order to create the solution and  Console Application project, you have to go to the File | New | Project menu (see Figure 6) and select the appropriate items.

Figure 6

When the solution is created, you have to add the solution and the Console Application project to the VSS control system (see Figure 7).

Figure 7

The Log-on VSS database page will appear, and you have to enter the appropriate username and password (see Figure 8).

Figure 8

The Add to SourceSafe window is launched and you have to click on the OK button to successfully include the project in the VSS database (see Figure 9).

Figure 9

Initially, the files are in checked-out state (indicated with a small red check mark on the left-hand side of the file icon). If you want to check in this file, go to the Solution Explorer and right-click on the project node and select the Check-In option to launch the Check-in window (see Figure 10).

Figure 10

The checked-out state is indicated with a small blue padlock on the left-hand side of the file icon (see Figure 11).

Figure 11

Now let's go to the development1 machine, and open Visual Studio.NET 2005 IDE. Go to the File | Source Control | Launch Microsoft Visual SourceSafe menu to open the Visual SourceSafe Explorer to add the VSS database (see Figure 12).

Figure 12

The Add SourceSafe Database Wizard is launched. In the Database Selection, select the Connect to an existing database option and click on the Next button (see Figure 13).

Figure 13

In the Share Location, you have to browse to the location where the VSS database resides and click on the Next button (see Figure 14).

Figure 14

In the Database Connection Name, you have to enter a descriptive name for the VSS connection and click on the Next button to finish with the wizard (see Figure 15).

Figure 15

Open the Open Project window by using the File | Open | Project/Solution menu. Then, click on the SourceSafe (LAN) button on the left, and select the TestProject item (see Figure 16).

Figure 16

The Log On to Visual SourceSafe database window appears in order to enter the username and password for the database (see Figure 17).

Figure 17

Then navigate to the solution file in the VSS database (see Figure 18).

Figure 18

Click on the Open button to download the solution into the Visual Studio.NET (see Figure 19).

Figure 19

Now let's do the same operations in the development2 machine.

Now it's time to develop the solution using Visual SourceSafe tools by adding new classes, and building the solution. As illustrative purposes, the developer 1 and developer2 will develop the Calculator class which is responsible to implement basic arithmetic operations.

In the development1 machine, right-click on the project, then choose Add | New Item and select the Class item (see Figure 20).

Figure 20

You can see that the project node is checked-out mode (indicated by a red check mark on the icon) because it has been changed. The newly added Calculator.cs file is represented using a yellow plus sign on the icon (see Figure 21).

Figure 21

Now let's implement some functionality of this Calculator class (see Listing 1).

using System;

using System.Collections.Generic;

using System.Text;

 

namespace TestVSS_ConsoleApp

{

    public class Calculator

    {

        public int Add(int nValue1, int nValue2)

        {

            return nValue1 + nValue2;

        }

        public int Product(int nValue1, int nValue2)

        {

            return nValue1 * nValue2;

        }

    }

}

Listing 1

Now we need to build the solution, and check in the changes to the VSS database. Go to the TestVSS_ConsoleApp node in the Solution Explorer, right-click over it and select the Check In option. Then you can see the pending checkins in the Check In window (see Figure 22).

Figure 22

Click on the Check In button, and the VSS database is now updated.

Now we're going to see how the exclusive check-out mode works for the VSS database in a development team (see Figure 3). Now the developer1 and developer2 are responsible to work together on the Calculator.cs file. The developers1 begins his work by opening the Calculator.cs file and writing some code (then this file turns into checked-out mode for editing). If this file is not checked out to another user, then the operation will succeed (see Listing 2).

using System;

using System.Collections.Generic;

using System.Text;

 

namespace TestVSS_ConsoleApp

{

    public class Calculator

    {

        public int Add(int nValue1, int nValue2)

        {

            return nValue1 + nValue2;

        }

        public int Product(int nValue1, int nValue2)

        {

            return nValue1 * nValue2;

        }

        public int Subtraction(int nValue1, int nValue2)

        {

            return nValue1 - nValue2;

        }

    }

}

Listing 2

While developer1 is still working, developer2 comes in and wants to implement another method for the Calculator class. The developer2 opens the Calculator.cs file and when he begins to type, then a check out operation cannot be performed successfully because the file is exclusively checked out by developer1 (see Figure 23).

Figure 23

If you see the status of the file in the developer2's Visual Studio.NET, you can see that is checked out by another user (see Figure 24).

Figure 24

Now developer1 checks in the project, and then developer2 needs to see the new status of the file, the project or the solution by right click on the underlying node and selecting the Refresh and Get Latest Version options. Now developer2 can add his code for the Calculator.cs file (see Listing 3).

using System;

using System.Collections.Generic;

using System.Text;

 

namespace TestVSS_ConsoleApp

{

    public class Calculator

    {

        public int Add(int nValue1, int nValue2)

        {

            return nValue1 + nValue2;

        }

        public int Product(int nValue1, int nValue2)

        {

            return nValue1 * nValue2;

        }

        public int Subtraction(int nValue1, int nValue2)

        {

            return nValue1 - nValue2;

        }

        public int Division(int nValue1, int nValue2)

        {

            return nValue1 / nValue2;

        }

    }

}

Listing 3

If you want to see the changes related to Calculator.cs file, right-click over the node and select the View History option. The History Option window will appear and then click on the OK button (see Figure 25).

Figure 25

And the final result is displayed in the History of Project window (see Figure 26).

Figure 26

You can also see the differences between the last version of your workspace and the final version in the database by clicking on the Diff button in the History window (see Figure 27).

Figure 27

Conclusion

In this article, I've shown how two developers can work together in a Visual Studio.NET project to cooperatively develop a solution using the source control operations. Now you can apply these techniques to your daily development activities.

Next Recommended Readings