Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all available .NET assemblies

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.

like image 872
Caerbanog Avatar asked Jan 30 '09 11:01

Caerbanog


1 Answers

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.

like image 135
Hans Passant Avatar answered Sep 21 '22 17:09

Hans Passant