How to get version of used dll

I am working on a set of web pages that use a shared library.
To test the deployment, I need to add version information to the generated html. A method that adds a version watermark to a page is a shared library.

So, I have something like this (this is harder because the shared library has a base class for web pages, but we can simplify it for this task):

In control from mainAssembly.dll, I call the OnInit method:

protected override void OnInit(EventArgs e) { .. Library.AddWatermark(this); .. } 

and in the shared library I have:

 public void AddWatermark(Control ctrl) { string assemblyVersion = GetAssemblyVersion(); ctrl.Controls.Add(new HiddenField { Value = string.Format("Version: {0}", assemblyVersion ) }); } 

So my question is: how to get the version of the assembly when we are in the method from this assembly? (in AddWatermark)? And if you can get the callerโ€™s build version? (MainAssembly)

+4
source share
2 answers

Try using

  Assembly.GetCallingAssembly(); Assembly.GetExecutingAssembly(); 
+3
source

Caller Build Version:

 Assembly assem = Assembly.GetCallingAssembly(); AssemblyName assemName = assem.GetName(); Console.WriteLine(assemName.Version.Major); Console.WriteLine(assemName.Version.Minor); 

To get the version of the current assembly, replace the first line of code with

 Assembly assem = Assembly.GetExecutingAssembly(); 
+7
source

Source: https://habr.com/ru/post/1341789/


All Articles