.net 如何最好地使用文件版本和程序集版本?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14770/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-03 09:38:32  来源:igfitidea点击:

How best to use File Version and Assembly Version?

.netattributesversions

提问by Rick

In .NET there are two version numbers available when building a project, File Version and Assembly Version. How are you using these numbers? Keeping them the same? Auto-incrementing one, but manually changing the other?

在 .NET 中,构建项目时有两个可用版本号,文件版本和程序集版本。你如何使用这些数字?保持它们相同?自动增加一个,但手动更改另一个?

Also what about the AssemblyInformationalVersionattribute?

还有AssemblyInformationalVersion属性呢?

I'd found this support Microsoft Knowledge Base (KB) article that provided some help: How to use Assembly Version and Assembly File Version.

我发现这篇支持 Microsoft 知识库 (KB) 的文章提供了一些帮助: How to use Assembly Version 和 Assembly File Version

采纳答案by Adam Haile

In a scenario where I have multiple file assemblies (i.e. 1 exe and 5 dlls) I will use a different file version for each, but the same assembly version for all of them, allowing you to know which exe each of the dlls go with.

在我有多个文件程序集(即 1 个 exe 和 5 个 dll)的情况下,我将为每个文件使用不同的文件版本,但对所有文件使用相同的程序集版本,让您知道每个 dll 使用哪个 exe。

回答by Jon Dewees

In solutions with multiple projects, one thing I've found very helpful is to have all the AssemblyInfo files point to a single project that governs the versioning. So my AssemblyInfos have a line:

在具有多个项目的解决方案中,我发现非常有用的一件事是让所有 AssemblyInfo 文件指向一个管理版本控制的项目。所以我的 AssemblyInfos 有一行:

[assembly: AssemblyVersion(Foo.StaticVersion.Bar)]

I have a project with a single file that declares the string:

我有一个带有声明字符串的单个文件的项目:

namespace Foo
{
    public static class StaticVersion
    {
         public const string Bar= "3.0.216.0"; // 08/01/2008 17:28:35
    }
}

My automated build process then just changes that string by pulling the most recent version from the database and incrementing the second last number.

我的自动构建过程然后只是通过从数据库中提取最新版本并增加倒数第二个数字来更改该字符串。

I only change the Major build number when the featureset changes dramatically.

我只在功能集发生巨大变化时更改主要版本号。

I don't change the file version at all.

我根本不更改文件版本。

回答by voyce

The KB article mentions the most important distinction: File versions are only used for display purposes, whereas the assembly version plays an important part in the .NET loading behaviour.

知识库文章提到了最重要的区别:文件版本仅用于显示目的,而程序集版本在 .NET 加载行为中起着重要作用。

If you change the assembly version number, then the identity of your assembly as a whole has changed. Developers will need to rebuild to reference your new version (unless you put some auto-versioning "policy" in place) and at runtime only assemblies with matching version numbers will be loaded.

如果更改程序集版本号,则整个程序集的标识已更改。开发人员需要重建以引用您的新版本(除非您设置了一些自动版本控制“策略”),并且在运行时只会加载具有匹配版本号的程序集。

This is important in my environment, where we need an incrementing, highly visible version number for audit purposes, but we don't want to force developers to rebuild or have many versions concurrently in production. In this case for backwardly-compatible minor changes we update the file version, but not the assembly version.

这在我的环境中很重要,我们需要一个递增的、高度可见的版本号用于审计目的,但我们不想强迫开发人员重建或在生产中同时拥有多个版本。在这种情况下,对于向后兼容的小改动,我们更新文件版本,而不是程序集版本。

回答by Mark Sowul

File versions are only used for display purposes, whereas the assembly version plays an important part in the .NET loading behaviour.

文件版本仅用于显示目的,而程序集版本在 .NET 加载行为中起着重要作用。

Not quite. The file version is also important for Windows Installer when you upgrade an existing version over a previous one.

不完全的。当您将现有版本升级到以前的版本时,文件版本对于 Windows Installer 也很重要。

回答by Philip Wallace

With my current application, each VS project has a link to an "AssemblyBuildInfo" source file which has the following attributes:

对于我当前的应用程序,每个 VS 项目都有一个指向“AssemblyBuildInfo”源文件的链接,该文件具有以下属性:

[assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyCompany("Acme Corporationy")]
[assembly: AssemblyCopyright("Copyright ?  2009 Acme Corporation")]

This way, all the assemblies in my solution share same version and company information (meaning if I have to change it, I change it only one time). By excluding the FileVersion, it is automatically set to the AssemblyVersion.

这样,我的解决方案中的所有程序集都共享相同的版本和公司信息(这意味着如果我必须更改它,我只更改一次)。通过排除 FileVersion,它会自动设置为 AssemblyVersion。

回答by Rick

@Adam: Are you changing the file version with each build? Are you using version control (SYN or VSS) and using that information to link source back to the binaries?

@Adam:您是否在每次构建时更改文件版本?您是否使用版本控制(SYN 或 VSS)并使用该信息将源链接回二进制文件?

Seems to make sense that the Assembly version stays the same. i.e. "2.0.0.0". That corresponds to the deployment of the product.

汇编版本保持不变似乎是有道理的。即“2.0.0.0”。这对应于产品的部署。

The file version changes to match the revision from the source control. "2.0.??.revision" This would provide a link from a specific dll (or exe) to the source that built it.

文件版本更改以匹配源代码管理中的修订。"2.0.??.revision" 这将提供从特定 dll(或 exe)到构建它的源的链接。

回答by Raffaeu

I wrote a blog post about this topic that may be useful to the community http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx

我写了一篇关于这个主题的博客文章,可能对社区有用http://blog.raffaeu.com/archive/2011/12/11/sharing-assembly-version-in-visual-studio-2010.aspx

回答by TheSmurf

I keep them the same. But then, I don't have multifile assemblies, which is when the AssemblyVersion number becomes important. I use Microsoft-style date encoding for my build numbers, rather than auto-incrementing (I don't find the number of times that something has been built to be all that important).

我让它们保持不变。但是,我没有多文件程序集,这是 AssemblyVersion 编号变得重要的时候。我使用 Microsoft 风格的日期编码作为我的构建号,而不是自动递增(我没有发现构建某些东西的次数那么重要)。