Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get the product version from a Razor View

I am trying to display my product version in a Razor view (_Layout.cshtml). I´m doing something like this:

<script>
alert('@FileVersionInfo.GetVersionInfo(Assembly.GetExecutingAssembly().Location).ProductVersion');
alert('@Assembly.GetExecutingAssembly().Location');
</script>

The problem is that the first alert showed me 0.0.0.0 then, I introduced the second alert and it shows me the following location:

C:WindowsMicrosoft.NETFramework644.0.30319Temporary ASP.NET Filesoot#35f35b93778aeaApp_Web_ztow0zpu.dll

Obviously this is not my assembly file. Is there any easy and clean way to get the assembly version from a Razor view?

like image 832
lontivero Avatar asked Nov 05 '12 19:11

lontivero


People also ask

How do I check the version of .NET core?

You can see both the SDK versions and runtime versions with the command dotnet --info .

What is the difference between file version and product version?

"Product Version" is the fully expanded Product version number which is set in the project. "File Version" will compress the Product Version removing the zeros that precede the value for a specific field and adding a zero for fields that have not been set, and then displays the compressed four field product version.

What does the Razor view engine consists of?

Razor View Engine is a markup syntax which helps us to write HTML and server-side code in web pages using C# or VB.Net. It is server-side markup language however it is not at all a programming language.

What is assembly versioning in C#?

The assembly's version number, which, together with the assembly name and culture information, is part of the assembly's identity. This number is used by the runtime to enforce version policy and plays a key part in the type resolution process at run time.


1 Answers

Edited for better answer

I am guessing that it is trying to get the version of the Razor Engine, not your application. So a workaround is to get this info in the controller and send it to the view through a viewbag.

In your controller add -

ViewBag.Version = System.Reflection.Assembly.GetExecutingAssembly().GetName().Version;

In your view add -

<h1>@ViewBag.Version</h1>
like image 101
Ben Jones Avatar answered Oct 20 '22 09:10

Ben Jones