theKindOfMe

April 27, 2009

Automate adding/using of the SVN revision to/as the version of a .net project, through a build target

Filed under: Uncategorized — Tags: , , — yasi8h @ 11:16 am

a bit too complex title eh? sorry about that. i am finally blogging about something after a long while. its a good idea to use the revision number of your source tree in thee release versions of your software. because it will enable you to ‘connect and identify’ your release versions with your source tree’s different revisions. this is how i went about ‘automating’ it. note that I use svn as my source control system, and VS(2008) as my IDE at work.

What we are trying to do

Read the AssemblyInfo.cs file in a project and replace the(/a part of the) version number for that project with it’s svn revision number.

What you need

Code

<!-- Import of the MSBuildCommunityTask targets -->
<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />

  <!-- to AssemblyInfo to include svn revision number -->
<Target Name="BeforeBuild">
	<SvnVersion LocalPath="$(MSBuildProjectDirectory)" ToolPath="$(ProgramFiles)\VisualSVN\bin">
	   <Output TaskParameter="Revision" PropertyName="Revision" />
        </SvnVersion>

	<FileUpdate Files="Properties\AssemblyInfo.cs"
                Regex="(\d+)\.(\d+)\.(\d+)\.(\d+)"
                ReplacementText="$1.$2.$3.$(Revision)" />
</Target>

Steps

  • Locate and open your project file. ex:- exampleProject.csproj in a editor.
  • Edit(SvnVersion node’s ToolPath attribute) the path of the svn bin folder, where you find the executables(ex: svn.exe, svnversion.exe…).
  • go the very end and add the following code to the file. be sure to add this code before the </project> tag closing. so that your code is still inside the <project> node.
  • Save the exampleProject.csproj file.
  • it’s done! now every time you build your project, it’s AssemblyInfo.cs file’s version will contain the svn revision number as it’s last part(x.x.x.svn-revison)

How

Let me start by saying that I am no expert in MSBuild(reffer MSDN for more info). MSBuild is the build system used by VS to build your projects. when you create a project file it is basically a MSBuild file. the build file tell MSBuild how your project should be build/compiled and about any other actions that needs to taken to insure a succesful build. when we needed to include the svn revision number of our project in the AssemblyInfo.cs file we simply added a build target called AssenblyInfo. inside that we uses two MSBuild CommunityTasks(“The MSBuild Community Tasks Project is an open source project for MSBuild tasks. The goal of the project is to provide a collection of open source tasks for MSBuild.“).

  • SvnVersion – “Summarize the local revision(s) of a working copy.” – we use this to get the svn revision of our project. the result(revision) is stroed in a property called Revision.
  • FileUpdate – “Replace text in file(s) using a Regular Expression.” – we use this task to replace the revision portion of the version string(x.x.x.revision) with the content of the Revision property.

and that’s it. pretty simple eh!

References

November 14, 2008

Setting up Perl in windows(for running vss2svn)

Filed under: Uncategorized — Tags: , , , — yasi8h @ 3:29 pm

recently at my workplace, i had to look in to, moving existing sources in vss, to svn. i have been using svn for a while now. both personally and at work. all i can say is its a pretty neat source controlling system. there is some hype about GIT. but i have not tried it yet. gotta give it a try sometime.

so when it comes to moving your existing source code from vss to svn, there are couple of utilities that you can use for this task. after doing some research. i settled down with vss2svn. it seemed to me that vss2svn is a mature up to date, maintained tool than the rest. however this is what i think. so if you are attempting to do a vss to svn migration you better do your own research and find out. vss2svn is basically a perl script. and it also includes another program called ssphys. ssphys is a c++ program that is suppose to deal with all the ‘talking to vss’.

i wanted to use the latest available source for vss2svn. but unfortunately there was no release or up to date nightly build in the site. so the only option was to build it from source. i am sure it won’t be a big deal if you are going to do this in a *nix box. but as for me i had to do it in a windows box. which required me to install perl and do something to get the necessary environment ready. you can get the latest source through the svn repo.

Building ssphys on windows

follow the instructions on how to do this at pumacode.

Setting up Perl in windows

  1. get activestate perl and install it.
  2. you will need to install some perl modules that are not installed by default in order to run the script(vss2svn). some of these modules are not installable via the activestate package manager. so you will have to use the cpan shell(this comes with the activestate perl distribution) to install these. btw i am assuming that you have some vc++ compiler installed on your box(ie: vs2005 with vc++). you will need this when you use the cpan shell. as it compiles perl modules from source(and some perl modules have source code written in c…).
  3. in a command shell, go to perl install directory(ex:- cd C:\perl) and type cpan. now you should be in the cpan shell.
  4. you can install all the dependencies of the script(vss2svn) at once by using (inside the cpan shell)ex:-    force install DBI DBD::SQLite2 Time::CTime Config::INI Text::Glob Digest::MD5 Data::UUID
  5. please check whether these modules are already installed or not in your activestate perl distribution. you can do this via the activestate package manager.(accessible via the start menu….).
  6. i have use the force key word above because some tests failed during the installation of perl modules. using the force key word will ignore test failures and install the packages anyways.
  7. although the devnotes.txt(that comes with the source code of the script. in the vss2svn directory of the main source tree. get it through svn…) says ‘Config::Ini is needed’, its really Config::INI. note the letter case. you will have to use Config::INI when you are installing it through cpan or else cpan would say there is no such package(or something similar…)


btw i have updated the pumacode wiki with these notes of mine.

now you should be good to go. good luck with running vss2svn! 🙂

Create a free website or blog at WordPress.com.