Rhonda
Rhonda

Reputation: 985

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().GetName().Version.ToString()) to display it. I thought about using ViewData but still not sure how to format the HTML to get it to display.

Upvotes: 6

Views: 12229

Answers (2)

A-Sharabiani
A-Sharabiani

Reputation: 19329

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")]

Upvotes: 4

Necros
Necros

Reputation: 3034

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

Upvotes: 12

Related Questions