【问题标题】:How to read the assembly version using Reflection?如何使用反射读取汇编版本?
【发布时间】:2022-12-12 21:44:53
【问题描述】:

我从我在 Blazor WebAssembly 应用程序中使用的 NuGet 包中获得了一个 .dll。我希望能够阅读它的版本。

目前我读的版本是这样的:

FileVersionInfo fileVersionInfo = FileVersionInfo.GetVersionInfo(Path.Combine(contentRootPath, @"bin\debug\net6.0\AssemblyName.dll"));
var version = $"{fileVersionInfo.FileDescription} ({fileVersionInfo.FileVersion})";

而不是写这样的路径 bin\debug\net6.0\AssemblyName.dll 我怎样才能加载程序集并使用反射来获取版本?

【问题讨论】:

  • 试试typeof(ClassFromPackage).GetAssembly().GetName().Version
  • 我不能在这样的声明中调用 GetAssembly()

标签: c# .net-core reflection


【解决方案1】:

我设法使用typeof(ClassFromPackage).Assembly.GetName().Version 解决了我的问题。

【讨论】:

    猜你喜欢
    • 2012-06-01
    • 1970-01-01
    • 2010-09-06
    • 2010-10-26
    • 2011-08-09
    • 1970-01-01
    • 2016-12-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多