简体   繁体   中英

C# Application - Custom Assembly Version Format

Bit of an odd one maybe, but currently looking into if it is possible to implement a custom format for the Assembly Information for a project.

In the Assembly information you are given the option of a 4 number system, so major.minor.build.revision

I have been asked to try and change this to a 5 number system, so something like 1.2.34.556.1234 and wondering whether this is even possible.

I have simply tried just modifying it programmatically, but that just returns the error:

Error emitting 'System.Reflection.AssemblyVersionAttribute' attribute -- 'The version specified '1.2.34.556.1234' is invalid'

For that purpose, I prefer using the AssemblyFileVersion instead of the AssemblyVersion .

The former has an open format and can accommodate virtually any additional information, whereas the latter, AssmeblyVersion is intended for use by the .NET framework and enforces a strict numbering scheme that yields compiler errors if infracted.

[assembly: AssemblyVersion("4.0.*")] //Strict Format, for framework use
[assembly: AssemblyFileVersion("4.0.20.110708")]    //Flexible Format more suitable for product versions

Update: Per OP comment, here is how one can access this attribute easily via reflection:

Assembly assembly = Assembly.GetExecutingAssembly();
FileVersionInfo fvi = FileVersionInfo.GetVersionInfo(assembly.Location);
string version = fvi.FileVersion;

This will not work because the constructor for AssemblyVersionAttribute takes up to 4 values in the string.:

The format of the version string is: major. minor. build. revision.

MSDN Link

AssemblyVersionAttribute is converted to the Version class .

It has only the major,minor,build,revision number: you cannot use 5 numbers.

If you want to use more numbers you can use the AssemblyInformationalVersion

It is not a Version Class but a string for a more descriptive assembly versioning:

[assembly: AssemblyInformationalVersion("1.12.0.3050.1234 Release - Any CPU")]

But you should provide anyway AssemblyVersion and/or AssemblyFileVersion without the 5th number

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM