在已编译的.NET程序集中更改程序集版本

时间:2022-01-23 06:29:46

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.

我实际上可以改变程序集文件版本。

6 个解决方案

#1


34  

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.

我们总是递增文件版本,这反映了内部版本号。

#2


5  

Old topic but here are my 5 dimes...

老话题,但这里是我的5角钱......

  1. Disassemble

    拆卸

    ildasm my.exe /output:my.il /metadata

    ildasm my.exe /output:my.il/ metadata

  2. Edit my.il to change version information. There are several places to look into:

    编辑my.il以更改版本信息。有几个地方需要研究:

    • major:minor:revision:build - usually one occurrence
    • major:minor:revision:build - 通常是一次出现
    • 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:
    • major.minor.revision.build - 几次出现。该字符串位于实际行之后的注释部分中。版本是字节数组中的十六进制值。例:

.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 35 2E 31 2E 33 2E 30 00 00 ) // ...5.1.3.0..

.custom instance void [mscorlib] System.Reflection.AssemblyFileVersionAttribute ::。ctor(string)=(01 00 07 35 2E 31 2E 33 2E 30 00 00)// ... 5.1.3.0 ..

  1. Edit my.res to change version information. Double click and edit with visual studio. Pretty straight forward procedure.

    编辑my.res以更改版本信息。双击并使用visual studio进行编辑。非常直接的程序。

  2. Assemble

    集合

    ilasm my.il /res:my.res

    ilasm my.il /res:my.res

#3


4  

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 redirection instead.

你为什么要这样做?如果它是另一个应用程序可以使用它,您可能希望查看程序集绑定重定向。

#4


1  

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 Whittaker gives 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 MSBuild or NAnt.

一旦有了单个文件,就可以通过使用MSBuild或NAnt使构建过程更新单个AssemblyInfo版本来获得额外的距离。

#5


1  

If you have formal testing and source control, the process becomes fairly straightforward. It starts with an understanding of who can change the differnt 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.

第一个段包含主版本号。这是由上层管理人员设置的,表示用户界面或应用平台的重大变化。程序集版本和文件版本之间的数字应始终相同。

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.

我发现这有助于部署者,测试人员和开发人员跟踪最新版本,而无需踩到彼此的脚趾。不幸的是,我还与使用静态版本控制系统的公司合作,这样就没有人真正知道最新,最好的组装是什么。

#6


1  

VerPatch, as referenced in this answer, is simple and effective.

如本答案所述,VerPatch简单有效。

#1


34  

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.

我们总是递增文件版本,这反映了内部版本号。

#2


5  

Old topic but here are my 5 dimes...

老话题,但这里是我的5角钱......

  1. Disassemble

    拆卸

    ildasm my.exe /output:my.il /metadata

    ildasm my.exe /output:my.il/ metadata

  2. Edit my.il to change version information. There are several places to look into:

    编辑my.il以更改版本信息。有几个地方需要研究:

    • major:minor:revision:build - usually one occurrence
    • major:minor:revision:build - 通常是一次出现
    • 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:
    • major.minor.revision.build - 几次出现。该字符串位于实际行之后的注释部分中。版本是字节数组中的十六进制值。例:

.custom instance void [mscorlib]System.Reflection.AssemblyFileVersionAttribute::.ctor(string) = ( 01 00 07 35 2E 31 2E 33 2E 30 00 00 ) // ...5.1.3.0..

.custom instance void [mscorlib] System.Reflection.AssemblyFileVersionAttribute ::。ctor(string)=(01 00 07 35 2E 31 2E 33 2E 30 00 00)// ... 5.1.3.0 ..

  1. Edit my.res to change version information. Double click and edit with visual studio. Pretty straight forward procedure.

    编辑my.res以更改版本信息。双击并使用visual studio进行编辑。非常直接的程序。

  2. Assemble

    集合

    ilasm my.il /res:my.res

    ilasm my.il /res:my.res

#3


4  

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 redirection instead.

你为什么要这样做?如果它是另一个应用程序可以使用它,您可能希望查看程序集绑定重定向。

#4


1  

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 Whittaker gives 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 MSBuild or NAnt.

一旦有了单个文件,就可以通过使用MSBuild或NAnt使构建过程更新单个AssemblyInfo版本来获得额外的距离。

#5


1  

If you have formal testing and source control, the process becomes fairly straightforward. It starts with an understanding of who can change the differnt 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.

第一个段包含主版本号。这是由上层管理人员设置的,表示用户界面或应用平台的重大变化。程序集版本和文件版本之间的数字应始终相同。

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.

我发现这有助于部署者,测试人员和开发人员跟踪最新版本,而无需踩到彼此的脚趾。不幸的是,我还与使用静态版本控制系统的公司合作,这样就没有人真正知道最新,最好的组装是什么。

#6


1  

VerPatch, as referenced in this answer, is simple and effective.

如本答案所述,VerPatch简单有效。