我只是想知道如何使用Visual Studio(2005)自动增加文件的构建(和版本?)

如果我查找C:\Windows\notepad.exe的属性,版本选项卡给出“文件版本:5.1.2600.2180”。我想在我的dll的版本中也得到这些很酷的数字,而不是版本1.0.0.0,让我们面对它有点沉闷。

我尝试了一些东西,但它似乎没有开箱即用的功能,或者可能我只是在错误的地方(像往常一样)。

我主要工作与网络项目....

我看了两个:

http://www.codeproject.com/KB/dotnet/Auto_Increment_Version.aspx http://www.codeproject.com/KB/dotnet/build_versioning.aspx

我不敢相信花这么大力气做一件事是标准做法。

编辑: 据我所知,它在VS2005中不工作(http://www.codeproject.com/KB/dotnet/AutoIncrementVersion.aspx)


当前回答

AssemblyInfoUtil。免费的。开源的。

其他回答

我已经创建了一个应用程序来自动增加文件版本。

下载应用程序 将以下行添加到预构建事件命令行 C: \ temp \ IncrementFileVersion.exe $ (SolutionDir) \ \ AssemblyInfo.cs属性 构建项目

为了简单起见,应用程序只在出现错误时抛出消息,为了确认它工作正常,你需要在“装配信息”中检查文件版本

注意:您必须在Visual studio中重新加载“装配信息”按钮来填充字段,但是您的输出文件将具有更新版本。

如有任何建议和要求,请发电子邮件至telson_alva@yahoo.com

也许,对于这个任务,你可以使用这样的代码:

    private bool IncreaseFileVersionBuild()
    {
        if (System.Diagnostics.Debugger.IsAttached)
        {
            try
            {
                var fi = new DirectoryInfo(AppDomain.CurrentDomain.BaseDirectory).Parent.Parent.GetDirectories("Properties")[0].GetFiles("AssemblyInfo.cs")[0];
                var ve = System.Diagnostics.FileVersionInfo.GetVersionInfo(System.Reflection.Assembly.GetExecutingAssembly().Location);
                string ol = ve.FileMajorPart.ToString() + "." + ve.FileMinorPart.ToString() + "." + ve.FileBuildPart.ToString() + "." + ve.FilePrivatePart.ToString();
                string ne = ve.FileMajorPart.ToString() + "." + ve.FileMinorPart.ToString() + "." + (ve.FileBuildPart + 1).ToString() + "." + ve.FilePrivatePart.ToString();
                System.IO.File.WriteAllText(fi.FullName, System.IO.File.ReadAllText(fi.FullName).Replace("[assembly: AssemblyFileVersion(\"" + ol + "\")]", "[assembly: AssemblyFileVersion(\"" + ne + "\")]"));
                return true;
            }
            catch
            {
                return false;
            }
        }
        return false;
    }

从form loading调用它。 使用这段代码,您可以更新AssemblyInfo.cs中的文件信息的任何部分(但必须使用“标准”目录结构)。

每次构建时,它都会自动增加最低有效位数。

我不知道如何更新其他的,但你至少应该已经看到了……

我使用这种方法https://stackoverflow.com/a/827209/3975786通过将T4模板放在“解决方案项”中,并在每个项目中使用“作为链接添加”。

设置版本号为“1.0”。*”,它会自动填充最后两个数字的日期(天从某个点)和时间(半秒从午夜)