Search code examples
.netversionassemblyinfo

Is there a way to display less than 4 numbers in the assembly version?


I need to display only 3 numbers for my assembly versions, to comply with our internal guidelines

I tried removing the last digit from the AssemblyInfo file to look like this

[assembly: AssemblyVersion("0.5.0")]
[assembly: AssemblyFileVersion("0.5.0")]

And I display it like this

Assembly.GetExecutingAssembly().GetName().Version.ToString();

However, it renders all four version numbers (0.5.0.0)

Is there a way to limit it to 3 without changing the code?

ie: only by editing the AssemblyInfo.cs or web.config file


Solution

  • Without code, no.

    You can use Reflector to see the implementation of Version.ToString(), and it always shows all four elements.

    But there is an overload Version.ToString(int) that will show a specified number of components.

    To choose dynamically you will need to write a method (possible an extension method) yourself.