开发者

How to get version of used dll

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();


Try to use

        Assembly.GetCallingAssembly();
        Assembly.GetExecutingAssembly();
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜