Using Subversion With Nant: Automated Checkouts From Config File

This is the first part of a I HAVE NO CLUE HOW MANY part thing involving Nant and how to use it to make your life easier. Of course you might wonder why I’m using Nant over say MSBuild, (Though I’m sure you were actually wondering if you really can get ripped in two weeks) and I have no real reason other than at some point this will tie into Cruise Control for easy deployments. Fact is, the debate between nant and msbuild is an ongoing war between the hopeless broken records known as Microsoft haters and the mindless Microbots. Personal, I don’t really care since they are both fine. I may some day switch to MSBuild but for the scope of this article that MIGHT BE A BIT STUPID AND HYPOCRITICAL.

Also you might wonder about why I’m using subversion instead of say Team Foundation Server. (And no you can’t get ripped in two weeks) Probably has to do with the 10k I don’t have to shell out for something that is about two generations behind subversion… and that’s saying something since subversion is about two generations behind source control in general. But my subversion hosting is 3.95 a month. So it really comes down to what is the only thing that matters when developing: Money.

Say you have someone new coming in and you want to be able to have said person be able to get a project from a subversion repository without really thinking. (You can’t assume new people think.) This is mostly helpful because chances are you’re place of employment is a revolving door just like every other place. So the thought of automation comes to mind. What if I told you getting things from a subversion repository is as easy as a config file? “Balderdash!”, you say. “The f— is balderdash?”, I reply. And at somepoint we talking an common language and I show you this:

<project name="ToolInstall" default="download">
  <property name="toolProject" value="ToolsProject" />
  <property name="svnLocation" value="c:\program files\subversion\bin\svn.exe" />

  <target name="clean" description="cleans build directory">
    <delete dir="${toolProject}" verbose="false" failonerror="false"/>
  </target>

  <target name="download" description="gets projects from repository" depends="clean">
   <exec program="${svnLocation}" commandline="checkout http://some.repository.com/trunk/src/ToolProject ToolProject --username tool --password somepassword"/>
  </target>
</project>

What’s all of this? Well I am here to break it down. Oh Oh Whoooaaa.

<project name="ToolInstall" default="download">

First element of the file has to be project. The name isn’t all that important to this example, however Default means whith taget it will run first if you don’t tell it.

  <property name="toolProject" value="ToolsProject" />
  <property name="svnLocation" value="c:\program files\subversion\bin\svn.exe" />

Think of a Property as a variable. They just allow you to take out as many repeated strings as possible. You’ll see that the svnLocation Property points to where subversion was installed. This will vary per computer if you didn’t specify the name of the install directory.

  <target name="clean" description="cleans build directory">
    <delete dir="${toolProject}" verbose="false" failonerror="false"/>
  </target>

A target is basically a task you need to have done. It could be anything from deleting junk, running tests, or getting you a date. (HAHA ITS FUNAY CAUSE THATS IMPOSSIBLE) For this one, it is simply removing a folder that may exist. You can use this same idea to remove bin and obj folders if you use nant to build your project or simply clean it… But I’ll get to building in another post.

  <target name="download" description="gets projects from repository" depends="clean">
   <exec program="${svnLocation}" commandline="checkout http://some.repository.com/trunk/src/ToolProject ToolProject --username tool --password somepassword"/>
  </target>

And there’s the best part of the post, using nant to grab something from a subversion repository. As you can see, I’ve used the svnLocation property to make it easier to set what Program to use. I think this target is pretty much self explanitory for anyone with an IQ higher that that of a potato.

Next step is just to create a batch file to call nant and run this config file. Let’s assume you called it Nant.install. I know, it’s so descriptive, it’s genius. Shut up, I get the sarcasm.

Here’s the batch file:

@..\nant\nant.exe -buildfile:Nant.install

Mind you @..\nant\nant.exe will change depending where your copy of nant.exe is, but I figured I leave that in the way it is just to show that it doesn’t have to reside in the same place.

And there you have it, subversion and nant together like two children frolicking in the forests of Bavaria. (Assuming they have forests there and me mentioning kids isn’t creepy) In my next post I’ll probably go more into nant itself, this was just kind of on a whim. And I don’t know why I am appologizing for this. Stop f—ing judging me.

2 thoughts on “Using Subversion With Nant: Automated Checkouts From Config File”

Comments are closed.