6

Pretty simple one: I have the following version number with an rc suffix in my project file. This is allowed according to this document and it compiles without warning.

<PropertyGroup>
    <Version>3.0.2.1294-rc</Version>
</PropertyGroup>

When accessing said version information with the line enter image description here

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

Andy
  • 6,366
  • 1
  • 32
  • 37

2 Answers2

5

I think you may be looking for this attribute:

Assembly.GetExecutingAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
radoslawik
  • 915
  • 1
  • 6
  • 14
0

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.

Timothy G.
  • 6,335
  • 7
  • 30
  • 46
  • The `FileVersionInfo` line was sourced from: https://stackoverflow.com/a/1605873/6530134 which is part of `System.Diagnostics`. If you don't want to do that, you could do what [radoslawik said](https://stackoverflow.com/a/73474279/6530134), in combination with this substring logic. – Timothy G. Aug 24 '22 at 13:53