【发布时间】: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