4

在更新在预构建事件期间运行的构建增量程序时,我注意到一个潜在的问题,它可能会导致相当多的问题。第一次构建应用程序成功更新BuildInfo.cs并计算了所有 const 值。每次后续构建和成功执行预构建事件都会更新正确的文件(如下所示),但每个计算的 const 值都与上次构建相比已过期。

// In externally modified file BuildInfo.cs which is updated by our pre-build
// tool to update the version information and produce new consts.
namespace ConstProblem.Properties {
  static class BuildInfo {
    internal const string AssemblyVersionString = "1.1.0.0";
    internal const string BuildDate = "2012-11-07T08:52:32.5480259-07:00";
    internal const string FileVersionString = "1.1.12312.852";
    internal const string Full = "v1.1 (Build: 2012-11-07 08:52)";
    internal const string Short = "1.1";
  }
}

// Program.cs. Reproduces the problem for this question.
namespace ConstProblem {
  class Program {
    const string UserAgent = "ConstProblem/" + Properties.BuildInfo.Short;

    static void Main() {
      System.Console.WriteLine(UserAgent);
    }
  }
}

例如,该应用程序最初是使用AssemblyVersionStringat构建的1.0.0.0。上述程序按预期运行和编译。将其增加到 1.1 并第二次构建/运行应用程序ConstProblem/1.0作为它的输出并具有这个作为它的值

// From the Immediate Window
Properties.BuildInfo
ConstProblem.Properties.BuildInfo
    base {object}: object
    AssemblyVersionString: "1.1.0.0"
    BuildDate: "2012-11-07T08:51:46.8404556-07:00"
    FileVersionString: "1.0.12312.851"
    Full: "v1.0 (Build: 2012-11-07 08:51)"
    Short: "1.0"

如您所见,已正确AssemblyVersionString更新1.1.0.0,但其余计算值未正确更新。如果我要第三次构建和执行(并增加到 1.2),它们将更新到上面提供的信息。

我已经确认预构建事件的输出文件正确输出了所有信息并以状态 0 退出以允许构建继续。我不知道为什么 const 总是落后。构建实用程序也是我编写的,它只是使用模板并在文件被签出时替换 BuildInfo.cs 的内容。

我的环境正在运行 Visual Studio 2010 Ultimate 并在 .Net 4 中编译。我已经在控制台和 Web 应用程序中重现了这一点。我从如何获取您自己的程序集的程序集版本和文件版本?

4

1 回答 1

0

它正在从 AssemblyInfo.cs 读取成功的构建增量,但是在成功构建后只会增加 1,因此为什么你总是落后 1。

[assembly: AssemblyVersion("1.star.star.star")]添加到AssemblyInfo.cs(在解决方案/属性中)

^ star = * (editor limitation)
于 2013-07-30T16:00:44.170 回答