列出所有可用的 .NET 程序集
列出所有可用的 .NET 2.0 程序集的最佳方法是什么?
所需列表的一个示例是当您在 .NET 选项卡中执行“添加引用...”时 MS Visual Studio 显示的列表。
我读过 Visual Studio 使用它自己的目录配置、GAC 和 .NET 安装。 我如何以计算机便携方式知道该目录的位置(另一台计算机可能在 D: 驱动器中安装了 Windows)有什么想法吗?
从列出的信息来看,必须可以对其进行 Assembly.Loadxxxx() 。
注意:它应该以编程方式完成,而不是使用 gacutil(除非它提供 C# API)。 所有这一切的目的是创建一个自定义动态脚本编辑器,以便您了解获取此信息的必要性。
What is the best way to list all available .NET 2.0 assemblies?
An example of the list needed is the one MS Visual Studio shows when you do 'Add Reference...' in the .NET tab.
I have read Visual studio uses its own directory configuration and the GAC another and .NET instalation another. Any ideas of how I can know where this directories are in a computer portable way (another computer might have windows installed in D: drive for example)?
From the information listed it must be possible to Assembly.Loadxxxx() it.
Note: It should be done programatically and not using gacutil for example (unless it provides a C# API). The objective of all this is to create a custom dynamic script editor so you understand the need to get to this information.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
首先,参考程序集和 GAC 中的程序集之间存在重要区别。 要编译代码,您需要一个参考程序集。 要运行代码,您需要与 .exe 位于同一文件夹中的程序集副本或 GAC 中的程序集。
通常,当您安装 .NET 应用程序时,其安装程序将复制它在 GAC 中使用的程序集。 这些程序集不能用作参考程序集,您无法找到它存储在哪个文件夹中,因此您无法告诉编译器其 /reference 命令行参数的正确值。 嗯,你可以找到答案,但微软试图通过 shell 插件让它尽可能地困难。
当您安装允许您在自己的程序中使用其程序集的 .NET 应用程序时,会发生一些不同的情况。 就像.NET框架一样。 它将为每个程序集制作两份副本。 一个位于 GAC,另一个位于“众所周知”的位置。 对于 .NET 框架,这些众所周知的位置是 c:\windows\microsoft.net\ 和 c:\program files\reference assembly。 .NET 3.0 及更高版本开始使用后一个文件夹。
Visual Studio 的“添加引用”对话框使用列出这些众所周知位置的注册表项。 有几个,但最重要的是
HKLM\Software\Microsoft\.NETFramework\AssemblyFolders
。长话短说:您可以使用该注册表项生成与“添加引用”对话框生成的列表相同的列表。 但它并不是 100% 可靠,您可能会错过某些产品在其他地方复制的参考程序集。 您必须使用 VS 中的“浏览”选项卡来添加对这些内容的引用。 并搜索整个磁盘以找到它们。
First of all, there's an important difference between reference assemblies and assemblies in the GAC. To compile code, you need a reference assembly. To run code, you need either a copy of the assembly in the same folder as your .exe or the assembly in the GAC.
Normally, when you install a .NET application, its installer will copy the assemblies it uses in the GAC. Those assemblies are not usable as reference assemblies, you can't find out in what folder it is stored so you can't tell the compiler the proper value of its /reference command line argument. Well, you can find out but Microsoft tried to make it as hard as possible with a shell add-in.
Something different happens when you install a .NET application that allows you to use its assemblies in your own program. Like the .NET framework. It will make two copies of every assembly. One goes in the GAC, the other goes in a "well-known" location. For the .NET framework, these well-known locations are c:\windows\microsoft.net\ and c:\program files\reference assemblies. The latter folder started getting used by .NET 3.0 and up.
Visual Studio's Add Reference dialog uses a registry key that lists these well-known locations. There are a couple, but the important one is
HKLM\Software\Microsoft\.NETFramework\AssemblyFolders
.Long story short: you could use that registry key to produce the same list that the Add Reference dialog produces. But it is not 100% reliable, you might miss reference assemblies that some product copied somewhere else. You'd have to use the Browse tab in VS to add references to those. And search the entire disk to find them yourself.
自从这个出现以来。 我会给出答案。 我在搜索其他内容时注意到了这一点,并且它出现了,尽管它已经有 13 年历史了。
具体来说,在 powershell 中,您可以查看所有加载的程序集,
因为这是加载的程序集,您也可以加载更多内容并搜索它们。
如果您想知道这些程序集中的类型,请
注意 GetTypes() 是百科全书式的大小响应。
最后,如果这些请求对您很重要,您应该知道这一点,但是您可以通过以下方式获取特定程序集的类型:
将 system.dll 替换为您想要深入了解的 dll,但可以节省屏幕空间。
如果您在
GetType()
方法上使用Select-String
,则只需搜索assemblequalifiedname
属性即可进行查找。 例如日期时间或数学如果您不记得它的名称,但知道它与数学有关,您可以使用
另一种简单的方法是只需键入
since this popped up. I will put an answer. I noticed this while searching other stuff, and it came up, even though it's 13 years old.
Specifically in powershell you can view all loaded assemblies with
Since this is loaded assemblies, you can load more and search through them too.
if you wish to know the types inside these assemblies you can use
be aware the GetTypes() is an encyclopedic size response.
Also finally, you should know this if these requests matter to you, but you can get the types of a specific assembly via:
replace system.dll with the dll you want to drill into but save screen space.
If you use
Select-String
on theGetType()
method, you will simply search theassemblyqualifiedname
attribute so you can hunt things down. such as datetime or mathIf you can't remember the name of it, but know it's something around math, you can use
Another easy way is to just type