如何在dll文件中获取类之类的信息?

问题描述 投票:0回答:2

我有一个.net框架dll文件,它有一些类。

我想使用powershell来获取.dll文件中所有类的名称,我该怎么办?

更新:

当我尝试使用import-module "xxxxx"时,它有以下错误。

enter image description here

powershell
2个回答
2
投票

我想你可以这样做:

$Assembly = [System.Reflection.Assembly]::LoadFrom('c:\temp\file.dll')
$Assembly.DefinedTypes
$Assembly.GetExportedTypes()
$Assembly.GetLoadedModules()

1
投票

另一种方法:使用Import-Module导入DLL并调用程序集的GetTypes()。像这样,

PS C:\> import-module "C:\Program Files (x86)\Microsoft SQL Server\140\Tools\Binn\ManagementStudio\Microsoft.SqlServer.Smo.dll"
PS C:\> $smo = ([appdomain]::CurrentDomain.GetAssemblies()) | ?{ $_.modules.name.contains("SqlServer") }
PS C:\> $smo.gettypes() | ? { $_.isPublic -and $_.isClass }
© www.soinside.com 2019 - 2024. All rights reserved.