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


当前回答

在visual Studio 2008中,下面的作品。

找到AssemblyInfo.cs文件并找到这两行:

[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]

您可以尝试将其更改为:

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

但是这不会给你想要的结果,你最终会得到一个1.0的产品版本。*和文件版本为1.0.0.0。不是你想要的!

然而,如果你去掉第二行,只有:

[assembly: AssemblyVersion("1.0.*")]

然后,编译器将文件版本设置为等于产品版本,您将得到您想要的结果,即自动递增的产品和文件版本是同步的。例如1.0.3266.92689

其他回答

我想出了一个类似于基督徒的解决方案,但不依赖于社区MSBuild任务,这对我来说不是一个选择,因为我不想为我们所有的开发人员安装这些任务。

我正在生成代码并编译到程序集,并想自动增加版本号。但是,我不能使用VS 6.0。* AssemblyVersion技巧,因为它每天自动递增构建号,并破坏与使用旧构建号的程序集的兼容性。相反,我希望有一个硬编码的AssemblyVersion,但要有一个自动递增的AssemblyFileVersion。我通过在AssemblyInfo.cs中指定AssemblyVersion并在MSBuild中生成一个VersionInfo.cs来实现这一点,

  <PropertyGroup>
    <Year>$([System.DateTime]::Now.ToString("yy"))</Year>
    <Month>$([System.DateTime]::Now.ToString("MM"))</Month>
    <Date>$([System.DateTime]::Now.ToString("dd"))</Date>
    <Time>$([System.DateTime]::Now.ToString("HHmm"))</Time>
    <AssemblyFileVersionAttribute>[assembly:System.Reflection.AssemblyFileVersion("$(Year).$(Month).$(Date).$(Time)")]</AssemblyFileVersionAttribute>
  </PropertyGroup>
  <Target Name="BeforeBuild">
    <WriteLinesToFile File="Properties\VersionInfo.cs" Lines="$(AssemblyFileVersionAttribute)" Overwrite="true">
    </WriteLinesToFile>
  </Target>

这将生成一个VersionInfo.cs文件,该文件具有AssemblyFileVersion的Assembly属性,其中版本遵循带有构建日期的YY.MM.DD.TTTT模式。您必须在项目中包含此文件并使用它进行构建。

从现在开始,对于我的申请,

string ver = Application.ProductVersion;

返回ver = 1.0.3251.27860

3251是自1/1/2000以来的天数。我使用它将版本创建日期放在应用程序的启动屏幕上。当与用户打交道时,我可以询问创建日期,这比一些长数字更容易沟通。

(我是一个支持小公司的个人部门。这种方法可能不适合你。)

如其他文章所述,在AssemblyInfo中的版本号中或在项目属性下设置*并不适用于所有版本的Visual Studio / . net。

Afaik,它在2005年的比赛中不起作用(但在2003年和2008年的比赛中不起作用)。对于VS 2005,你可以使用以下方法:在编译时自动增加Visual Studio 2005版本的构建和修订号。

But be aware that changing the version number automatically is not recommended for strong-named assemblies. The reason is that all references to such an assembly must be updated each time the referenced assembly is rebuilt due to the fact that strong-named assembly references are always a reference to a specific assembly version. Microsoft themselves change the version number of the .NET Framework assemblies only if there are changes in interfaces. (NB: I'm still searching for the link in MSDN where I read that.)

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

我用Visual Studio 2019尝试了这一点,但它不起作用。 在较新的VS版本中,至少确定性标志阻止了自动更新。但是改变了第14行 您的项目名。csproj到<Deterministic>false</Deterministic> . csproj到<Deterministic>false</Deterministic> . csproj到 并将版本号字符串更改为“1.0”。*”并没有帮到我。

所以我做了一个小vbs脚本来完成这项工作。 它将版本号更改为(主要版本)。(小版本)。[一][dayofyear])。(增量)。

将脚本复制到一个文件夹中,并将以下内容放入pre-compile build-commandline:

"Path-to-this-script\UpdateVersion.vbs"  "$(ProjectDir)"

(包括报价和填写您机器的真实路径) 和你完成了。

在这里获取: https://github.com/abtzero/VS_UpdateVersion.git