Print Version Number in ASP.NET MVC 4 app

前端 未结 7 2022
灰色年华
灰色年华 2020-12-23 19:15

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 \

7条回答
  •  悲哀的现实
    2020-12-23 19:18

    Your assembly version may be set using the AssemblyFileVersionAttribute, which must be accessed specifically.

    AssemblyFileVersionAttribute attr = typeof(MyController).Assembly.GetCustomAttributes(typeof(AssemblyFileVersionAttribute), true).OfType().FirstOrDefault();
    
    if (attr != null)
    {
        return attr.Version;
    }
    

    The MvcDiagnostics Nuget package makes this simple.

提交回复
热议问题