我只是想知道如何使用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)


当前回答

它在项目属性下的Publish中

(~ http://screencast.com/t/Vj7rhqJO)

其他回答

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

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

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

    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中的文件信息的任何部分(但必须使用“标准”目录结构)。

转到项目|属性,然后是程序集信息,然后是程序集版本,在最后一个或倒数第二个框中放入*(不能自动增加主要或次要组件)。

使用MSBuild Community Tasks (http://msbuildtasks.tigris.org/)项目中的AssemblyInfo任务,并将其集成到.csproj/中。vbproj文件。

它有许多选项,包括将版本号与日期和时间联系起来。

推荐。

在VS2012中可以更改AssemblyInfo。奇怪的是,Visual Studio中对此没有更多的支持,你会认为这是构建/发布过程的基本部分。