Showing the version number of the currently deployed application

by Oliver 7. October 2011 22:27

Yesterday I just quickly wanted to add the version number of our new Todo management application to the footer of every page. I could have just checked our own blog history or went off to Google or Stackoverflow but I just wanted to do it myself. Simple enough, isn’t it?

To get the assembly of the web application from inside a view, for example, unfortunately this won’t work:


It will print out something like  Version: App_Web_xu4dep5e, Version=, Culture=neutral, PublicKeyToken=null

Well, this is the dynamically compiled dll for just my view – not what I’m looking for.

The following does the trick:


This prints  Version: Todo.Web, Version=, Culture=neutral, PublicKeyToken=null.

So now, the only thing left is to get the version number from the assembly. Should be easy, there should be some kind of property named Version, or a method called GetVersion() right? Well, there isn’t:


Looking at the AssemblyInfo.cs, I saw that the AssemblyVersion is an attribute on the assembly:


So I thought the following code would work, but it didn’t (throws on .First() with System.InvalidOperationException: Sequence contains no elements):


In the end, the solution is really short but not quite intuitive. Why is Version a member of the type AssemblyName which you access by calling GetName()? I don’t know.


Happy Coding!

enjoyed the post?


Add comment

  Country flag

  • Comment
  • Preview

About Oliver code blog logo I build web applications using ASP.NET and have a passion for javascript. Enjoy MVC 4 and Orchard CMS, and I do TDD whenever I can. I like clean code. Love to spend time with my wife and our children. My profile on Stack Exchange, a network of free, community-driven Q&A sites

About Anton code blog logo I'm a software developer at teamaton. I code in C# and work with MVC, Orchard, SpecFlow, Coypu and NHibernate. I enjoy beach volleyball, board games and Coke.