JQuery Mobile JQuery Mobile - 3 months ago 38
C# Question

Print Version Number in ASP.NET MVC 4 app

I have an ASP.NET MVC 4 application. Currently, I am setting the version of the application in the project properties under the "Application" tab. From here, I click the "Assembly Information..." button. Once there, I have entered "1 0 0 *" in the "Assembly version" field.

My question is, how do I show this value on my web page? Currently, I am trying the following

@System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()


Unfortunately, it's always printing "0.0.0.0". Realistically, I'd like to have it print 1.0.0.xyz. I would also like to print the date/time when the last build occurred. However, I have no idea how to do that.

What am I doing wrong?

Answer

To print the version number of the assembly in which was defined the controller that rendered this view:

@ViewContext.Controller.GetType().Assembly.GetName().Version

and for the assembly date:

@File.GetCreationTime(ViewContext.Controller.GetType().Assembly.Location)
Comments