Using the Web Application version number from an assembly (ASP.NET/C#)

后端 未结 12 973
我寻月下人不归
我寻月下人不归 2020-12-07 18:39

How do I obtain the version number of the calling web application in a referenced assembly?

I\'ve tried using System.Reflection.Assembly.GetCallingAssembly().GetName

12条回答
  •  轻奢々
    轻奢々 (楼主)
    2020-12-07 19:14

    The question states with no reference (instances) it did not (originally) say with no knowledge of web application types.

    EDIT the OP clarified to state that yes they do really require no knowledge of types within the calling web assembly, so the answer is appropriate. However I would seriously consider refactoring such a solution such that the version is passed into the other assembly.

    For most people in this scenario if you know the custom HttpApplication type:

     typeof(MyHttpApplication).Assembly.GetName().Version
    

    and if you only have a dynamic generated type:

     typeof(DynamiclyGeneratedTypeFromWebApp).BaseType.Assembly.GetName().Version
    

    Stop voting me down for this answer :)

提交回复
热议问题