3

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

juan
  • 80,295
  • 52
  • 162
  • 195
  • 1
    Assembly number consists of four parts and you won't change that. Why don't you just change the code? Since you are allowing AssemblyInfo.cs change it means that you are allowed to recompile the code, right? – Miha Markic Apr 30 '09 at 13:38

1 Answers1

5

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.

Richard
  • 106,783
  • 21
  • 203
  • 265