4
votes

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

2

2 Answers

5
votes

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.

0
votes

Try this:

var assemblies = AppDomain.CurrentDomain.GetAssemblies();