有没有办法检索 ASP.NET 5 Web 应用程序的产品版本?
这是我的 project.json
中的内容:
"version": "4.0.0-alpha1"
我怎样才能从应用程序中检索到它?我曾经能够在旧的 ASP.NET 版本上执行此操作:
System.Reflection.Assembly.GetExecutingAssembly().GetName().Version
但是,现在它一直给我 0.0.0.0
。有什么想法吗?
最佳答案
如果您还没有,请在您的 project.json 文件中添加对 System.Reflection
的引用。
"dependencies": {
"System.Reflection": "4.1.0-beta-23516" // Current version at time of posting
}
然后,您可以从 AssemblyInformationalVersionAttribute 中获取值InformationalVersion
属性。
private static string GetRuntimeVersion() =>
typeof(SomeClassInYourAssembly)
.GetTypeInfo()
.Assembly
.GetCustomAttribute<AssemblyInformationalVersionAttribute>()
.InformationalVersion;
关于c# - 如何检索产品版本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35903625/