List all available .NET assemblies
Asked Answered
C

2

13

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.

Congratulatory answered 30/1, 2009 at 11:38 Comment(0)
C
10

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.

Commutative answered 30/1, 2009 at 19:50 Comment(1)
Just tried the last point in your answer and did not work. System.dll is for example not included in any of the paths found at HKLM\Software\Microsoft\.NETFramework\AssemblyFoldersPapyrus
V
2

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

[System.AppDomain]::CurrentDomain.GetAssemblies()

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

[System.AppDomain]::CurrentDomain.GettAssemblies().GetTypes()

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:

([System.AppDomain]::CurrentDomain.GetAssemblies() | where Location -match system.dll).GetTypes()

replace system.dll with the dll you want to drill into but save screen space.

If you use Select-String on the GetType() method, you will simply search the assemblyqualifiedname attribute so you can hunt things down. such as datetime or math

If you can't remember the name of it, but know it's something around math, you can use

([System.AppDomain]::CurrentDomain.GetAssemblies()).gettypes() | sls math

Another easy way is to just type

[math] # now press tab while your cursor is over the word math multiple times to see what comes out
Verse answered 30/4, 2022 at 4:2 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.