Here's a C# class we use to parse out SVN info from the working copy .svn
folders.  Once we have this a simple regex replace is used on the
version.asfile within our build script.  Some build toold like cruse
control.net provide version stamping built in.  Ant might do it as well, not
sure.

HTH,

Sam


using System;
using System.Collections.Generic;
using System.IO;

namespace
{
    public class SvnInfo
    {
        #region Data

        private string _workingCopy;
        private int _format;
        private int _revision;
        private string _url;
        private string _rootUrl;

        #endregion

        #region Parse

        public static SvnInfo Parse()
        {
            return Parse(Environment.CurrentDirectory);
        }

        public static SvnInfo Parse(string path)
        {
            if (String.IsNullOrEmpty(path))
            {
                throw new ArgumentNullException("path");
            }
            if (!Directory.Exists(path))
            {
                throw new ArgumentException("The specified path does not
exist.", path);
            }
            SvnInfo info = new SvnInfo();
            info._workingCopy = path;
            string svnPath = Path.Combine(path, ".svn");
            if (!Directory.Exists(svnPath))
            {
                svnPath = Path.Combine(path, "_svn");
                if (!Directory.Exists(svnPath))
                {
                    throw new ArgumentException(
                        "The specified path is not a subversion working
copy--no '.svn' or '_svn' subdirectory found.",
                        path);
                }
            }

            string entriesPath = Path.Combine(svnPath, "entries");
            if (!File.Exists(entriesPath))
            {
                throw new ArgumentException(
                    "The specified path is not a recognized subversion
working copy--no entries file found.",
                    path);
            }
            List<string> lines = new List<string>(5);
            using (StreamReader reader = new StreamReader(entriesPath))
            {
                string line;
                int i = 6;
                while ( (line = reader.ReadLine()) != null && i-- > 0)
                {
                    lines.Add(line);
                }
            }

            info._format = info.ParseInt(lines[0]);
            info._revision = info.ParseInt(lines[3]);
            info._url = lines[4];
            if (lines.Count > 5)
            {
                info._rootUrl = lines[5];
            }
            return info;
        }

        private int ParseInt(string text)
        {
            int i;
            if (int.TryParse(text, out i))
            {
                return i;
            }
            throw new ArgumentException(
                String.Format(
                    "The specified path is not a recognized subversion
working copy--expected a number but found '{0}'.", text),
                _workingCopy);
        }

        #endregion

        #region Properties

        public string WorkingCopy
        {
            get
            {
                return _workingCopy;
            }
        }

        public int Format
        {
            get
            {
                return _format;
            }
        }

        public int Revision
        {
            get
            {
                return _revision;
            }
        }

        public string Url
        {
            get
            {
                return _url;
            }
        }

        public string RootUrl
        {
            get
            {
                return _rootUrl;
            }
        }

        #endregion

    }
}



On Feb 18, 2008 8:34 PM, essuark <[EMAIL PROTECTED]> wrote:

> That is a pretty good idea... Any place you can point me to that show
> this scripting build process?
>

Reply via email to