We have a webapplication which doesn't use MVC. This webapplication is already using an Assembly.cs. In my C# code I can get the version number of the webapplication, but how to get it in the webpage (.cshtml)?

I tried using

@System.Reflection.Assembly.GetExecutingAssembly().GetName();

but it returns

t0cxczo0, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null

Not something which looks familiar.

When I use

@typeof(MyApp.Application).Assembly.GetName()

It compiles fine, but at run-time I get

"Cannot find namespace MyApp"

MyApp is the name of my application and Application is one of my classes.

I also tried

@System.Diagnostics.FileVersionInfo.GetVersionInfo(typeof(MyApp.Application).Assembly.Location).ProductVersion

But that also returns the "Cannot find namespace MyApp" error.

My webapplication uses some other home-made binaries which are reused across other webapplications. When I use

@System.Reflection.Assembly.GetCallingAssembly().GetName()

I'm getting the name and version of the other assembly that is handling the template stuff. So I'm getting close ;)

When I use

@System.Reflection.Assembly.GetEntryAssembly().GetName()

I get a "Template Execution" error

When I use

@HttpContext.Current.ApplicationInstance

I'm getting an error about HttpContext doesn't exists.

Please advice how to do this should-be-easy task.

Related posts

Recent Viewed