Print Version Number in ASP.NET MVC 4 app
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)
I usually make HtmlHelper
extension for this purpose. Something like this:
public static class HtmlHelperExtensions
{
public static IHtmlString AssemblyVersion(this HtmlHelper helper)
{
var version = Assembly.GetExecutingAssembly().GetName().Version.ToString();
return MvcHtmlString.Create(version);
}
}
And than inside view you just call:
@Html.AssemblyVersion()