Home > Blockchain >  .NET Core display Assembly Version
.NET Core display Assembly Version

Time:07-06

In ASP.Net MVC, It's easy to display on a page a websites version/build #. The '*' allows a new hash value for each build, thus it is easy to tell what version a running website corresponds to for a specific build checked into source control. Is there an equivalent type of functionality in .NET Core?

ASP.Net MVC:
AssemblyInfo.cs

// Version information for an assembly consists of the following four values:
//
//      Major Version
//      Minor Version 
//      Build Number
//      Revision
//
// You can specify all the values or you can default the Build and Revision Numbers 
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.*")]

Index.cshtml

<footer>
    <p>&copy; @DateTime.Now.Year - @Html.AssemblyVersion()</p>
</footer>

CodePudding user response:

In ASP.NET core MVC app, you can do like this.

public class VersionHelper
{
    public static string GetAssemblyVersion()
    {
        AssemblyInformationalVersionAttribute infoVersion = (AssemblyInformationalVersionAttribute)Assembly.GetExecutingAssembly().GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false).FirstOrDefault();
        return infoVersion.InformationalVersion;
    }
}

and in Index.cshtml or _layout.cshtml, wherever your footer is defined.

<footer>
    <p>&copy; @DateTime.Now.Year - @VersionHelper.GetAssemblyVersion()</p>
</footer>
   
  • Related