ASP.NET MVC version number from AssemblyInfo.cs

So I want to set the version in the AssemblyInfo.cs file and display it on the site.

I found this wonderful library.

NuGet: ApplicationAssemblyUtility

Code and Files.

~/AssemblyInfo.cs

1
[assembly: AssemblyVersion("1.0.1.5")]

~/Global.asax.cs

Class property

1
public static ApplicationAssemblyDetails ApplicationAssemblyDetails { get; set; }

In Application_Start

1
ApplicationAssemblyDetails = ApplicationAssemblyDetails.Current;

~/Helpers/ApplicationAssemblyDetails.cs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
using eSpares.Levity;
namespace YourAppNameSpace.Helpers
{
public class ApplicationAssemblyDetails
{
public static ApplicationAssemblyDetails Current
{
get
{
return new ApplicationAssemblyDetails
{
VersionNumber = ApplicationAssemblyUtility.GetApplicationVersionNumber(),
BuildMode = ApplicationAssemblyUtility.ApplicationIsDebugBuild() ? "Debug" : "Release"
};
}
}

public string VersionNumber { get; set; }
public string BuildMode { get; set; }
public override string ToString()
    {
    if (ApplicationAssemblyUtility.ApplicationIsDebugBuild())
      {
      return string.Format("{0} ({1})", VersionNumber, BuildMode);
      }
      else
      {
      return VersionNumber;
      }
    }
  }
}

~/Views/Shared/_Layout.html

1
@MvcApplication.ApplicationAssemblyDetails

That’s it!