MartinDotNet
MartinDotNet

Reputation: 2505

Can I get all assemblies referenced by a website

Basically, I want to print a list on a page inside my MVC site that shows all the assemblies that are used by the application and there version information.

I don't want to just include those in the bin directory, I want to use a more accurate way.

So examples would be

I want to know which dll's within the bin directory are being used. For each of these, I need to see what their dependent assemblies are (with their version information).

I want to know which dll's are referenced from GAC, etc.

I want as much information on this as possible, so information like what version the assembly is expecting, and what the application is picking up would be useful.

Are there any standard approaches to this?

Thanks, Martin

Upvotes: 5

Views: 670

Answers (2)

Ricardo Peres
Ricardo Peres

Reputation: 14535

Try this:

var assemblies = AppDomain.CurrentDomain.GetAssemblies();

Upvotes: 0

Konrad Kokosa
Konrad Kokosa

Reputation: 16878

Consider using BuildManager.GetReferencedAssemblies which:

Returns a list of assembly references that all page compilations must reference.

Example usage:

var assemblies = BuildManager.GetReferencedAssemblies().Cast<Assembly>();

Note also an important difference between this method and AppDomain.GetAssemblies(). BuildManager.GetReferencedAssemblies returns:

assemblies specified in the assemblies element of the Web.config file, assemblies built from custom code in the App_Code directory, and assemblies in other top-level folders.

while AppDomain.GetAssemblies() returns only assemblies currently loaded.

Upvotes: 6

Related Questions