有三个程序集版本属性。什么是差异?是否可以使用AssemblyVersion而忽略其余部分?
MSDN说:
AssemblyVersion: 指定指定属性的程序集的版本。 AssemblyFileVersion: 指示编译器为Win32文件版本资源使用特定的版本号。Win32文件版本不需要与程序集的版本号相同。 AssemblyInformationalVersion: 定义程序集清单的其他版本信息。
本文是“使用程序集属性的最佳实践是什么?”
有三个程序集版本属性。什么是差异?是否可以使用AssemblyVersion而忽略其余部分?
MSDN说:
AssemblyVersion: 指定指定属性的程序集的版本。 AssemblyFileVersion: 指示编译器为Win32文件版本资源使用特定的版本号。Win32文件版本不需要与程序集的版本号相同。 AssemblyInformationalVersion: 定义程序集清单的其他版本信息。
本文是“使用程序集属性的最佳实践是什么?”
当前回答
为了使这个问题保持最新,值得强调的是,NuGet使用了AssemblyInformationalVersion,并反映了包含任何预发布后缀的包版本。
例如,1.0.3的AssemblyVersion。*与asp.net核心dotnet-cli打包
dotnet pack --version-suffix ci-7 src/MyProject
生成一个版本为1.0.3-ci-7的包,您可以使用以下方法进行反射检查:
CustomAttributeExtensions.GetCustomAttribute<AssemblyInformationalVersionAttribute>(asm);
其他回答
AssemblyVersion基本上是。net内部的,而AssemblyFileVersion是Windows所看到的。如果您转到位于目录中的程序集的属性并切换到版本选项卡,您将在顶部看到AssemblyFileVersion。如果您按版本对文件进行排序,这就是Explorer所使用的。
AssemblyInformationalVersion映射到“产品版本”,并意味着纯粹是“人类使用的”。
AssemblyVersion当然是最重要的,但我也不会跳过AssemblyFileVersion。如果您没有提供AssemblyInformationalVersion,编译器将为您添加它,方法是去掉版本号的“revision”部分,并保留major.minor.build。
当程序集的AssemblyVersion被更改时, 如果它具有强名称,则需要重新编译引用程序集,否则将无法加载程序集! 如果它没有强名称,如果没有显式地添加到项目文件中,它将不会在构建时复制到输出目录,因此您可能会错过依赖的程序集,特别是在清理输出目录之后。
还有一些值得注意的事情:
As shown in Windows Explorer Properties dialog for the generated assembly file, there are two places called "File version". The one seen in the header of the dialog shows the AssemblyVersion, not the AssemblyFileVersion. In the Other version information section, there is another element called "File Version". This is where you can see what was entered as the AssemblyFileVersion. AssemblyFileVersion is just plain text. It doesn't have to conform to the numbering scheme restrictions that AssemblyVersion does (<build> < 65K, e.g.). It can be 3.2.<release tag text>.<datetime>, if you like. Your build system will have to fill in the tokens. Moreover, it is not subject to the wildcard replacement that AssemblyVersion is. If you just have a value of "3.0.1.*" in the AssemblyInfo.cs, that is exactly what will show in the Other version information->File Version element. I don't know the impact upon an installer of using something other than numeric file version numbers, though.
当您通过Windows资源管理器通过查看文件属性查看文件的“版本”信息时,会显示AssemblyInformationalVersion和AssemblyFileVersion。这些属性实际上被编译到编译器创建的VERSION_INFO资源中。
AssemblyInformationalVersion是“产品版本”值。AssemblyFileVersion是“文件版本”值。
AssemblyVersion是特定于. net程序集的,. net程序集加载器使用它来了解在运行时加载/绑定程序集的哪个版本。
在这些属性中,. net唯一绝对需要的是AssemblyVersion属性。不幸的是,当它不加区别地更改时,也会导致大多数问题,特别是如果您对程序集进行了强命名的话。
为了使这个问题保持最新,值得强调的是,NuGet使用了AssemblyInformationalVersion,并反映了包含任何预发布后缀的包版本。
例如,1.0.3的AssemblyVersion。*与asp.net核心dotnet-cli打包
dotnet pack --version-suffix ci-7 src/MyProject
生成一个版本为1.0.3-ci-7的包,您可以使用以下方法进行反射检查:
CustomAttributeExtensions.GetCustomAttribute<AssemblyInformationalVersionAttribute>(asm);