开发者

How to display version number on the footer of an MVC3 app

While we are in dev and doing daily builds, we would like to display the current version number on the footer of the pages in our MVC3 app. Makes it easier for the QA to log bugs.

I'm not sure how to do this. The footer is in the shared _layout.cshtml page.

I would like to use (Assembly.GetExecutingAssembly().GetNam开发者_运维知识库e().Version.ToString()) to display it. I thought about using ViewData but still not sure how to format the HTML to get it to display.


Since you just need it in dev, you could simply do

<footer>
    @System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
</footer>

This used to work back in the day (i think).

Now it indeed does not, so use this instead (from the answer linked in the comment):

@typeof(YourApplicationNamespace.MvcApplication).Assembly.GetName().Version


I am using the code below which works fine for me:

<footer>
    @ViewContext.Controller.GetType().Assembly.GetName().Version
<footer>

To change the version, you can change this line in the AssemblyInfo.cs file of your project:

[assembly: AssemblyVersion("1.0.0.0")]
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜