通过构建应用程序自定义文件版本/exe 的产品版本

Custom File Version/ Product Version of exe by building an application

如标题所示,我需要通过从 Visual Studio.

构建项目来为应用程序分配自定义文件 and/or 产品版本

我知道您可以从应用程序发布中分配内部版本号,但我不会发布这些应用程序,我只是在构建 "release" 个文件。

Visual Studio 有没有办法在我构建应用程序之前指定这些文件版本?

提前致谢!

Is there a way within Visual Studio to specify these file versions before I build the application?

是的,您可以在构建应用程序之前通过 AssemblyInfo.cs 指定 File/Product 版本。

首先,文件版本在AssemblyInfo.cs文件中查找属性AssemblyFileVersion。所以你可以通过设置值AssemblyFileVersion来指定文件版本。我将 AssemblyFileVersion 值从 1.0.0.0 更改为 2.0.0.0:

[assembly: AssemblyFileVersion("2.0.0.0")]

其次,ProductVersion首先查看是否包含main的程序集 可执行文件具有 AssemblyInformationalVersion 属性。如果这 属性存在,它用于产品版本。 如果此属性不存在,则两个属性都使用 AssemblyFileVersion

因此,在您的项目中,打开 AssemblyInfo.cs 文件。在这个文件中,我添加了一个 像这样的行:

[assembly: AssemblyInformationalVersion("4.0.0.0")]

然后构建完成后。文件版本为 2.0.0.0,产品版本为 4.0.0.0