user659025
user659025

Reputation:

How do I get a list of all the assemblies I can reference on my machine?

To add a new .NET reference to your project in Visual Studio you just click "Add reference..." on References of the current project, switch to the ".NET" tab and go for it.

Now, is there a way to get this list programmatically?

Upvotes: 0

Views: 2663

Answers (3)

Tigran
Tigran

Reputation: 62246

I would go for fixed path, cause it can be subject of change, but insted for or use

GacUtil

example, from command line can use

gacutil /l > assemblylist.txt 

and assemblylist.txt will have a list of all assemblies in GAC with all information you need.


or can try to use

GAC Api (not documented one) You will need to do some interop on this, it's not C#.

Can try to use this C# warpper for it

GAC API Interface

Upvotes: 0

Matten
Matten

Reputation: 17631

Either access the global assembly cache with the gacutil or use a wrapper like introduced on this msdn page.

Upvotes: 0

Habib
Habib

Reputation: 223247

//You need to access GAC

List<string> gacFolders = new List<string>() { 
    "GAC", "GAC_32", "GAC_64", "GAC_MSIL", 
    "NativeImages_v2.0.50727_32", 
    "NativeImages_v2.0.50727_64" 
};

foreach (string folder in gacFolders)
{
    string path = Path.Combine(@"c:\windows\assembly", folder);
    if(Directory.Exists(path))
    {
        Response.Write("<hr/>" + folder + "<hr/>");

        string[] assemblyFolders = Directory.GetDirectories(path);
        foreach (string assemblyFolder in assemblyFolders)
        {
            Response.Write(assemblyFolder + "<br/>");
        }
    }
}

Source: enumerating assemblies in GAC

Upvotes: 4

Related Questions