如何在MVC3应用的页脚上显示版本号

问题描述

| 在进行开发并进行日常构建时,我们希望在MVC3应用程序页面的页脚中显示当前版本号。使质量检查人员更容易记录错误。 我不确定该怎么做。页脚位于共享的_layout.cshtml页面中。 我想使用(Assembly.GetExecutingAssembly()。GetName()。Version.ToString())来显示它。我曾考虑过使用ViewData,但仍不确定如何格式化HTML以使其显示。     

解决方法

由于您只需要在开发人员中使用它,因此您只需
<footer>
    @System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
</footer>
这曾经在一天中起作用(我认为)。 现在的确不是,所以使用它代替(从注释中链接的答案):
@typeof(YourApplicationNamespace.MvcApplication).Assembly.GetName().Version
    ,我正在使用下面的代码对我来说很好
<footer>
    @ViewContext.Controller.GetType().Assembly.GetName().Version
<footer>
要更改版本,可以在项目的
AssemblyInfo.cs
文件中更改此行:
[assembly: AssemblyVersion(\"1.0.0.0\")]