不含CC.NET的.NET程序集中的SVN修订版

时间:2020-03-05 18:39:52  来源:igfitidea点击:

有什么方法可以在.NET程序集的版本字符串中包含SVN存储库修订版号?诸如Major.Minor.SVNRev之类的东西

我已经提到过使用CC.NET之类的方法(尽管实际上是在ASP.NET上)进行此操作的方法,但是没有任何额外的软件有没有办法做到这一点?在使用构建批处理脚本之前,我已经在C / C ++中完成了类似的操作,但是通过读取版本号,然后让脚本每次都写出一个名为" ver.h"的文件来完成该操作,效果如下:

#define MAJORVER 4
#define MINORVER 23
#define SOURCEVER 965

然后,我们将使用这些定义来生成版本字符串。

.NET是否可能出现这种情况?

解决方案

回答

看看SubWCRev http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-subwcrev.html

程序集版本号通常在assemblyinfo.cs中

回答

svn信息,告诉我们所使用的版本,我们可以在VS上的项目上进行"预构建"事件,以通过运行svn信息并使用本地命令行应用程序解析其结果来生成assemblyinfo.cs。

我之前已经做过,但是很快切换到仅让ccnet将其作为变量传递给nant。

回答

如果要更新项目AssemblyInfo.cs中的版本号,则可能对本文感兴趣:

CodeProject:在Visual Studio项目中使用Subversion修订版号

If you enable SVN Keywords then every time you check in the project Subversion scans your files for certain "keywords" and replaces the keywords with some information.
  
  For example, At the top of my source files I would create a header contain the following keywords:
  
  '$Author:$

  '$Id:$

  '$Rev:$
  
  When I check this file into Subversion these keywords are replaced with the following:
  
  '$Author: paulbetteridge $

  '$Id: myfile.vb 145 2008-07-16 15:24:29Z paulbetteridge $

  '$Rev: 145 $

回答

阅读/略读这些文档:

使用DotSVN从.NET访问Subversion存储库

如何:编写任务

在CAssemblyInfo文件中插入SVN版本和内部版本号

使用自定义任务为Microsoft Build Engine编译应用程序

在第三个参考资料中提到的MSBuildCommunityTasks svnversion在Mac 10.5.6和托管Vista的Parallels内部(即,跨OS)的VS2008 Cproject上,不能与svn一起使用。

编写我们自己的任务,以使用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;
        }
    }
}

这样,存储库路径可以是" file:/// Y:/ repo",其中Y:是映射到Vista的Mac目录。

回答

有可能,但我们不应该这样做:程序集版本字符串的组件限制为16位数字(最大65535)。 Subversion修订版号可能会轻易变得更大,因此在某些时候,编译器会突然抱怨。

回答

我们可以使用共享的Assembly Version文件,我们可以在所有项目中引用该文件。

UppercuT这样做http://ferventcoder.com/archive/2009/05/21/uppercut---automated-builds---versionbuilder.aspx

这将使我们了解如何在程序集中获取版本。