SVN Revision Version in .NET Assembly w/ out CC.NET

前端 未结 8 1270
失恋的感觉
失恋的感觉 2020-12-23 11:55

Is there any way to include the SVN repository revision number in the version string of a .NET assembly? Something like Major.Minor.SVNRev

I\'ve seen mention of doi

8条回答
  •  长情又很酷
    2020-12-23 12:45

    Read/skim these docs:

    Accessing the Subversion repository from .NET using DotSVN

    How to: Write a Task

    Insert SVN version and Build number in your C# AssemblyInfo file

    Compiling Apps With Custom Tasks For The Microsoft Build Engine

    The MSBuildCommunityTasks svnversion mentioned in third reference would not perform with svn on Mac 10.5.6 and VS2008 C# project build inside Parallels hosting Vista (ie., across OS).

    Write your own task to retrieve revision from repository using DotSVN:

    using System;
    using Microsoft.Build.Framework;
    using Microsoft.Build.Utilities;
    using DotSVN.Common;
    using DotSVN.Common.Entities;
    using DotSVN.Common.Util;
    using DotSVN.Server.RepositoryAccess;
    
    namespace GetSVNVersion
    {
        public class GetRevision : Task
        {
            [Required]
            public string Repository { get; set; }
            [Output]
            public string Revision { get; set; }
    
            public override bool Execute()
            {
                ISVNRepository repo;
                bool connected = true;
                try
                {
                    repo = SVNRepositoryFactory.Create(new SVNURL(Repository));
                    repo.OpenRepository();
                    Revision = repo.GetLatestRevision().ToString();
                    Log.LogCommandLine(Repository + " is revision " + Revision);
                    repo.CloseRepository();
                }
                catch(Exception e)
                {
                    Log.LogError("Error retrieving revision number for " + Repository + ": " + e.Message);
                    connected = false;
                }
                return connected;
            }
        }
    }
    

    This way allows the repository path to be "file:///Y:/repo" where Y: is a Mac directory mapped into Vista.

提交回复
热议问题