I'm working on set of webparts that uses common library.
To testing deployment I need to add version info in generated html. Method that add version "watermark" to page is in common library.
So I have something like this (it is more complicated, because in common library is base class for webparts, but for this problem we can simplify it):
In control from mainAssembly.dll I'm calling OnInit method:
protected override void OnInit(EventArgs e)
{
..
Library.AddWatermark(this);
..
}
and in common 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 version of assembly when we are in method from this assembly? (in AddWatermark)? And if it is possible to get version of caller assembly? (mainAssembly)
Version of caller assembly:
Assembly assem = Assembly.GetCallingAssembly();
AssemblyName assemName = assem.GetName();
Console.WriteLine(assemName.Version.Major);
Console.WriteLine(assemName.Version.Minor);
To get version of current assembly replace first line of code with
Assembly assem = Assembly.GetExecutingAssembly();
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