skip to Main Content

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?

2

Answers


  1. I think you may be looking for this attribute:

    Assembly.GetExecutingAssembly()?.GetCustomAttribute<AssemblyInformationalVersionAttribute>()?.InformationalVersion
    
    Login or Signup to reply.
  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search