How to get product version from Razor View

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

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

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

C: WindowsMicrosoft.NETFramework644.0.30319 ASP.NET Technical Files # 35f35b93778aeaApp_Web_ztow0zpu.dll

Obviously, this is not my build file. Is there a simple and clean way to get the build version from a Razor view?

+7
source share
2 answers

Edited for a better answer

I assume that he is trying to get a version of Razor Engine, not your application. Therefore, a workaround is to get this information in the controller and send it to the presentation through the bag.

In the add controller -

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

In your opinion add -

 <h1>@ViewBag.Version</h1> 
+11
source

The answer is actually hidden, as ASP.NET processes each page / view (Razor view). It compiles each page / view into a separate dll. His name may be, as your question says:

 App_Web_j2tdatrx.dll 

And it really is placed inside (please take a look)

 c:\Windows\Microsoft.NET\Framework64\v4.0.30319\ 

So, if you want to get the version of the Internet assembly, you have to find it differently. Because it is not executive. To get the version in this case, do more reflection and find the library you want to show: for example. Firm.Product.Web.dll

+3
source

All Articles