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

后端 未结 12 1011
我寻月下人不归
我寻月下人不归 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:07

    I find that the simplest one-liner way to get the version of your "main" assembly (instead of the dynamic one) is:

    typeof(MyMainClass).Assembly.GetName().Version
    

    Use your top-level class, which isn't likely to ever "change its meaning" or to be replaced as part of a refactoring effort, as MyMainClass. You know in which assembly this very class is defined and there can no longer be confusion as to where the version number comes from.

提交回复
热议问题