Thursday, June 4, 2009

Developing with Visual Studio & Subversion

A reliable Version Control System is important to every development team. Generally speaking, Java developers are very familiar with CVS and Subversion, but .Net developers often use Microsoft SourceSafe to manage their code. However, SourceSafe is pretty bad. I see SourceSafe as a source code backup system more than a version control system (doing that, it really makes justice to its name).

So when I tried to make the jump to Subversion, I encountered a couple of issues. Now I’m posting this Tutorial about how to implement Subversion in .Net developments, just in case you need it.

In this tutorial we are going to use CollabNet products: its Subversion Server and Client and AnkhSVN subversion plugin for Visual Studio. I will use Visual Studio 2005, but it works for 2008, too.

First thing to do: install the Subversion Server.

1) Files you need: CollabNetSubversion-server-[version].win32.exe
Download it from here:
You are going to have to register, but it is free and quick.

2) Run collabNetSubversion installer and follow the steps.
You can use a server or just your local PC. It depends on the size of the team and the resources you have.

3) Select to install both components SVNSERVE and Apache (MOD_DAV_SVN) (Apache 2.2).

4) Select the port (default 3690, you may use this one) and a repository path (default c:\svn_repository) and select install svnserve to run as Windows Service.

5) Select Host for Apache (localhost or your IP) and host port (default 80, if IIS is installed or the port is already assigned select other, like 3128) and select install apache to run as windows service. Select the repository path for mod_dav_svn (the same as step 4) and the repository location prefix (default /svn). Enable viewVC is not necessary.

6) Select destination folder and click install.

Until this step, we already installed CollabNet’s Subversion Server, but we still have to do some configurations.

Configuring the Services

7) Open the Services tool (Administrative Tools->Services or Start->Run...->services.msc).
8) Look for Apache2.2 service and start the service.
9) Look for Subversion Server and start the service. You can see in the Properties of the service if the start up type is set to Automatic.

Setting Environment Variables

10) Go to My Computer -> right click -> properties -> advance-> environment variables.
11) Create a System variable called SVN_EDITOR as c:\windows\notepad.exe (or you can choose another text editor).
12) Verify the System variable Path and check there is C:\Program Files\CollabNet Subversion Server (the destination path of the installation). If it is not there, add it.

Creating the Repository

13) Open a Command Prompt.
14) type:
svnadmin create c:\svn_repository (the repository path you entered in the installation).
15) Navigate to c:\svn_repository and verify that a lot of files have been generated there.

Creating Users and Granting Access

16) Navigate to the c:\svn_repository\conf\svnserve.conf file and open it with notepad.
17) Uncomment (remove the # sign and the first blank space) the following lines:
anon-access = read
auth-access = write
password-db = passwd

18) The password-db variable is the file where the passwords are stored. Go there (c:\svn_repository\conf\passwd) and open it with notepad.
19) Uncomment (remove the # sign and the first blank space) the following lines:
[users] harry = harryssecret sally = sallyssecret
20) "harry" and "sally" are your user names with their passwords. You may delete them and create your own user names.

Creating a Project

21) Open a command prompt and type:
svn mkdir svn://ipaddress:port/myproject
Where "myproject" is the name of your project, "ipaddress" can be replaced with your IP address or "localhost" and "port" with the subversion server port.
22) Your notepad (or favorite text editor) will prompt you to add a comment. Add it, save it and close the window.
23) Now you'll be prompted for credentials. You may need to enter the password for your PC user account, then use harry or sally's username and password (or the ones you created).
24) Create the folders that by convention should be in a subversion project:
svn mkdir svn://ipaddress:port/myproject/trunk
svn mkdir svn://ipaddress:port/myproject/branches
svn mkdir svn://ipaddress:port/myproject/tags

25) Finally, to test that everything is OK, run this command:
svn ls svn://ipaddress:port/myproject

So far, you already set up a Subversion server, a repository with its users and a project.

In the next post we’ll see how to install and configure a Subversion client and a plugin for Visual Studio 2005.

Useful links about this topic:

No comments:

Post a Comment