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?
You can see both the SDK versions and runtime versions with the command dotnet --info .
"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.
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.
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.
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With