我希望能够在Linux环境中(也就是在运行任何mcr.microsoft.com/dotnet/core/sdk docker镜像时)获得任何dll的元数据(尽可能支持dotnet版本)。
这能实现吗?
说到元数据,我指的是我可以在不加载代码的情况下告诉它的所有事情(最重要的-命名空间,版本)。
我观察到了Assembly.ReflectionOnlyLoadFrom(),但它似乎不支持前dotnet核心版本。
我并不局限于一种编程语言,只限于基于Linux的运行时。
发布于 2019-10-30 07:55:13
使用Microsoft.CodeAnalysis.Common包中的AssemblyMetadata,您可以读取动态链接库的内容,如版本、模块、类型、引用、属性以及几乎所有内容
var path = @"path/to/dll/file.dll";
var metadata = AssemblyMetadata.CreateFromFile(path);
var module = metadata.GetModules().First();
Console.WriteLine(module.Name);
var reader = module.GetMetadataReader();
var assemblyDef = reader.GetAssemblyDefinition();
Console.WriteLine(reader.GetString(assemblyDef.Name));
Console.WriteLine(assemblyDef.Version.ToString());
foreach (var typeDefHandle in reader.TypeDefinitions)
{
var typeDef = reader.GetTypeDefinition(typeDefHandle);
var fullName = (reader.GetString(typeDef.Namespace) + "::" + reader.GetString(typeDef.Name));
Console.WriteLine(fullName);
}发布于 2019-10-28 16:39:22
我无法让任何标准工具在Windows之外工作(ilspy、dnspy、ildasm)
然而,在this question中引用的exiftool似乎可以很好地提供一些元数据,尽管它仍然有限。
exiftool Newtonsoft.Json.net45.dll的输出示例
ExifTool Version Number : 11.73
File Name : Newtonsoft.Json.net45.dll
Directory : .
File Size : 660 kB
File Modification Date/Time : 2019:04:22 02:06:26+03:00
File Access Date/Time : 2019:10:28 10:11:25+02:00
File Inode Change Date/Time : 2019:10:28 10:09:56+02:00
File Permissions : rwxr-xr-x
File Type : Win32 DLL
File Type Extension : dll
MIME Type : application/octet-stream
Machine Type : Intel 386 or later, and compatibles
Time Stamp : 2092:04:05 06:43:32+03:00
Image File Characteristics : Executable, Large address aware, DLL
PE Type : PE32
Linker Version : 48.0
Code Size : 665088
Initialized Data Size : 2048
Uninitialized Data Size : 0
Entry Point : 0xa42ba
OS Version : 4.0
Image Version : 0.0
Subsystem Version : 6.0
Subsystem : Windows command line
File Version Number : 12.0.2.23222
Product Version Number : 12.0.2.0
File Flags Mask : 0x003f
File Flags : (none)
File OS : Win32
Object File Type : Dynamic link library
File Subtype : 0
Language Code : Neutral
Character Set : Unicode
Comments : Json.NET is a popular high-performance JSON framework for .NET
Company Name : Newtonsoft
File Description : Json.NET
File Version : 12.0.2.23222
Internal Name : Newtonsoft.Json.dll
Legal Copyright : Copyright © James Newton-King 2008
Legal Trademarks :
Original File Name : Newtonsoft.Json.dll
Product Name : Json.NET
Product Version : 12.0.2+4ab34b0461fb595805d092a46a58f35f66c84d6a
Assembly Version : 12.0.0.0https://stackoverflow.com/questions/58581274
复制相似问题