I'm using the following code in a footer in my _Layout.cshtml file to put the AssemblyInfo version data into the footer of every page in my MVC3 site. However:
@System.Reflection.Assembly.GetExecutingAssembly().GetName().Version.ToString()
Just prints in the footer:
Revision 0.0.0.0
When I modified the view to display all of the assembly info for the "Executing Assembly" using the following
@System.Reflection.Assembly.GetExecutingAssembly().GetName().ToString()
Which prints the following:
Revision App_Web__layout.cshtml.639c3968.hlogy75x, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null
This shows that the "Executing Assembly" isn't my main app, it's the view itself.
How do I get the assembly information for the ACTUAL app, not just the individual views??
GO to Home Controller and just copy this code :
Rename
ActionResult
to StringYou need to get the assembly of a type in the project:
Where
MyType
is any type in the MVC project itself (eg, a controller or model, or theMvcApplication
class)Expanding on takepara's answer, if you want a one liner to get the AssemblyInformationalVersionAttribute from a MVC Razor View:
cshtml/vbhtml is dynamic compile to assembly.
how about this?
My problem was that I had renamed the namespace afterwards and I got the error above. The problem was the old namespace reference in the Views\Web.config . I had to change it from
Project.WebAPI17
toCompany.Project.WebAPI17
Using this helper works for me: