【问题标题】:What is the best way to implement versioning of a binary?实现二进制版本控制的最佳方法是什么?
【发布时间】:2009-06-11 15:19:12
【问题描述】:

我正在考虑以下设计:

static class AppVersion
{
     public static string BuildDate 
     {
       get; set;
     }
     public static string Version 
     {
       get; set;
     }
     public static string GetVersion 
     {
       get; set;
     }
}

关于这个的几个问题:

  1. 如何获取构建日期?
  2. 如何以良好的格式打印日期?
  3. 如何获取并打印格式良好的 Visual Studio 版本?
  4. 将版本硬编码到二进制文件中可能是个坏主意,因此我将版本放入汇编信息中。如何以编程方式获取它?

【问题讨论】:

标签: c# .net assemblies versioning


【解决方案1】:

我认为您的第一个问题是个人喜好问题。您可以使用String.Format 来获得您想要的任何样式。关于你的最后一个问题:

System.Reflection.Assembly.GetExecutingAssembly().Version

返回当前程序集的版本号并且:

typeof(SomeTypeInSomeAssembly).Assembly.Version

将返回包含特定类型的程序集的版本号。

【讨论】:

    【解决方案2】:

    我们通过 CruiseControl.NET 运行我们所有的生产构建,它(以及许多其他东西)具有版本构建的功能。

    然后,我们有一段代码在将 CC.NET 生成的内部版本号(和其他内容)应用到 AssemblyInfo.cs 之前,就在它被提供给编译器进行构建之前。

    我想您可以使用类似的技术将构建日期插入到应用程序某处某个类的常量中。

    【讨论】:

      【解决方案3】:

      对于构建日期,请查看 http://dotnetfreak.co.uk/blog/archive/2004/07/08/determining-the-build-date-of-an-assembly.aspx

      对于版本/获取版本,请查看 System.Reflection.Assembly 名称空间。

      至于以良好的格式打印日期,您需要使用从 DateTime 类构建的扩展方法,例如 .ToShortDateString() 或 CultureInfo。

      【讨论】:

        【解决方案4】:

        对于构建日期或时间戳,您可以在构建时将其嵌入到程序集中。
        如何做到这一点,see here

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 2010-09-09
          • 1970-01-01
          • 2010-10-11
          • 2018-11-23
          • 1970-01-01
          • 2011-07-01
          • 2011-01-02
          • 1970-01-01
          相关资源
          最近更新 更多