Home > database >  How do you get version number suffix from assembly version?
How do you get version number suffix from assembly version?

Time:08-25

Pretty simple one: I have the following version number with an rc suffix in my project file. This is allowed according to enter image description here

I don't see the suffix information anywhere. Anyone know a way to extract that suffix information?

CodePudding user response:

I think you may be looking for this attribute:

Assembly.GetExecutingAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion

CodePudding user response:

The only way I've been able to get the suffix is via substring logic. There doesn't seem to be any properties or members for any of the assembly types that contain just the suffix.

string productVersion = FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion; //sets productVersion to 3.0.2.1294-rc
string suffix = productVersion.Substring(productVersion.IndexOf('-')   1, productVersion.Length - productVersion.IndexOf('-') - 1);

This should set suffix to rc. Obviously this won't work if multiple hyphens are in the version information. However, if you are looking for a suffix you likely are always looking for the last one, so you could use .LastIndexOf() instead.

I would definitely do some error handling around this should you go this path.

  • Related