在已编译的 .NET 程序集中更改程序集版本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/398170/
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
Change Assembly Version in a compiled .NET assembly
提问by Mike
Simple question... is there a way to change the Assembly Version of a compiled .NET assembly?
简单的问题...有没有办法更改已编译的 .NET 程序集的程序集版本?
I'd actually be fine with a way to change the Assembly File Version.
我实际上可以通过更改程序集文件版本的方法来解决。
回答by MarkGr
You can use ILMerge:
您可以使用ILMerge:
ILMerge.exe Foo.dll /ver:1.2.3.4 /out:Foo2.dll
A valid reason to do this is to increment the assembly version in a build in you find breaking changes (using NDepend for example). That way if there are no breaking changes the assembly version stays the same, and you can patch released builds easily.
这样做的一个有效原因是在您发现破坏性更改的构建中增加程序集版本(例如使用 NDepend)。这样,如果没有重大更改,程序集版本将保持不变,您可以轻松修补已发布的版本。
We always increment the file version, and that reflects the build number.
我们总是增加文件版本,这反映了内部版本号。
回答by Georgi Atanassov
Old topic but here are my 5 dimes...
老话题,但这是我的 5 角钱……
Disassemble
ildasm my.exe /output:my.il /metadata
Edit my.ilto change version information. There are several places to look into:
- major:minor:revision:build - usually one occurrence
- major.minor.revision.build - several occurrences. The string is found in the comment section after the actual line. The version is a hexadecimal value in a byte array. Example:
拆卸
ildasm my.exe /output:my.il /metadata
编辑my.il以更改版本信息。有几个地方可以查看:
- 主要:次要:修订:构建 - 通常出现一次
- Major.minor.revision.build - 多次出现。该字符串位于实际行之后的注释部分。版本是字节数组中的十六进制值。例子:
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 352E 312E 332E 3000 00 ) // ...5.1.3.0..
.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 352E 312E 332E 3000 00 ) // ...5.1.3.0..
Edit my.resto change version information. Double click and edit with visual studio. Pretty straight forward procedure.
Assemble
ilasm my.il /res:my.res
编辑my.res以更改版本信息。双击并使用 Visual Studio 进行编辑。非常直接的程序。
集合
ilasm my.il /res:my.res
回答by Jon Skeet
Why do you want to do this? If it's so that another application can use it, you might want to look into assembly binding redirectioninstead.
你为什么要这样做?如果它是为了另一个应用程序可以使用它,您可能需要查看程序集绑定重定向。
回答by Jon Skeet
It sounds like your process is heavy because you have to update multiple AssemblyInfo files. Have you considered sharing the same AssemblyInfo file between projects? Derik Whittakergives a good example on how to do this.
听起来您的过程很繁重,因为您必须更新多个 AssemblyInfo 文件。您是否考虑过在项目之间共享相同的 AssemblyInfo 文件? Derik Whittaker给出了一个很好的例子来说明如何做到这一点。
Once you have a single file, you could then go the extra distance by having a build process update your single AssemblyInfo version using MSBuildor NAnt.
一旦你有了一个文件,你就可以通过让构建过程使用MSBuild或NAnt更新你的单个 AssemblyInfo 版本来走得更远。
回答by user1787189
If you have formal testing and source control, the process becomes fairly straightforward. It starts with an understanding of who can change the diferent number segments of the version, and when. .net assemblies have 4 number segments (i.e. 1.0.0.1).
如果你有正式的测试和源代码控制,这个过程就会变得相当简单。首先了解谁可以更改版本的不同数字段,以及何时更改。.net 程序集有 4 个数字段(即 1.0.0.1)。
The first segment contains the Major Version number. This is set by upper management and indicates a major change in the UI or in the platform of the app. This should always be same number between the assembly version and the file version.
第一段包含主要版本号。这是由上层管理人员设置的,表示 UI 或应用程序平台的重大变化。这在程序集版本和文件版本之间应该始终是相同的数字。
The second segment contains the Minor Version number, also known as the Feature Release number. This is set by Project Management and indicates that new features have been added to the app. This should always be same number between the assembly version and the file version.
第二部分包含次要版本号,也称为功能版本号。这是由项目管理设置的,表示应用程序中添加了新功能。这在程序集版本和文件版本之间应该始终是相同的数字。
The third segment contains the Build number. This is set by the testing group and indicates that the app is ready to be deployed. It is changed before bug fixes are released. When releasing a new build, testing resets the fourth segment to 0. This can be the same number between the assembly version and the file version, but is usually left at 0 for the assembly version to simplify patching existing deployments.
第三段包含内部版本号。这是由测试组设置的,表示应用程序已准备好部署。它在发布错误修复之前已更改。发布新版本时,测试将第四段重置为 0。这可以是程序集版本和文件版本之间的相同数字,但通常为程序集版本保留为 0,以简化对现有部署的修补。
The fourth segment contains the Revision number. This set by the development group whenever they check new code into source control. This number would be included in the file version of the compiled DLL, but not in the assembly version.
第四段包含修订号。这是由开发组在将新代码签入源代码管理时设置的。此数字将包含在已编译 DLL 的文件版本中,但不会包含在程序集版本中。
I have found that this helps deployers, testers and developers keep track of the latest versions without stepping on each others toes. Unfortunatley, I have also worked with companies that used a static versioning system so that nobody really knew what the latest, best assembly was.
我发现这有助于部署人员、测试人员和开发人员跟踪最新版本,而不会互相影响。不幸的是,我还与使用静态版本控制系统的公司合作过,因此没有人真正知道最新、最好的程序集是什么。

