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


当前回答

安装构建版本增量加载项。它给了你比*选项更多的控制。

其他回答

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

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

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

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

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

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

打开AssemblyInfo.cs文件并更改

// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

to

[assembly: AssemblyVersion("1.0.*")]
//[assembly: AssemblyFileVersion("1.0.0.0")]

你可以在IDE中通过项目->属性->程序集信息来做到这一点

但是,这将只允许您自动增加程序集版本,并将为您提供

程序集文件版本:该字段不允许使用通配符(“*”)

消息框,如果您尝试在文件版本字段中放置*。

因此,只需打开assemblyinfo.cs并手动执行。

在每次构建中更改版本号的另一个选项是使用MSBuild.Community.Tasks的version任务。只需下载他们的安装程序,安装它,然后调整以下代码,并将其粘贴到<Import Project="$(MSBuildBinPath)\Microsoft.CSharp。在你的。csproj文件中的Targets " />:

<Import Project="$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks.Targets" />
<Target Name="BeforeBuild">
    <Version VersionFile="Properties\version.txt" Major="1" Minor="0" BuildType="Automatic" StartDate="12/31/2009" RevisionType="BuildIncrement">
      <Output TaskParameter="Major" PropertyName="Major" />
      <Output TaskParameter="Minor" PropertyName="Minor" />
      <Output TaskParameter="Build" PropertyName="Build" />
      <Output TaskParameter="Revision" PropertyName="Revision" />
    </Version>
    <AssemblyInfo CodeLanguage="CS"
                  OutputFile="Properties\VersionInfo.cs"
                  AssemblyVersion="$(Major).$(Minor)"
                  AssemblyFileVersion="$(Major).$(Minor).$(Build).$(Revision)" />
</Target>

注意:根据您的语言环境调整StartDate属性。它目前不使用不变区域性。

对于2010年1月14日的第三个版本,这将创建一个包含以下内容的VersionInfo.cs:

[assembly: AssemblyVersion("1.0")]
[assembly: AssemblyFileVersion("1.0.14.2")]

然后必须将该文件添加到项目中(通过添加现有项),并且必须从AssemblyInfo.cs中删除AssemblyVersion和AssemblyFileVersion行。

用于更改版本组件的不同算法在$(MSBuildExtensionsPath)\MSBuildCommunityTasks\MSBuild.Community.Tasks中描述。chm和版本属性。

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

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