A simple question. I have an ASP.NET web application which contains several assemblies and I need to create a list of version information for every assembly in the web site. (And perhaps even a few others too, but the focus is mostly for the site itself.)
This list will be displayed within the same application on a protected page and is used to validate the installation and upgrades for the website. Of course, I could just walk through all binaries in the BIN folder and extract information from them but is there a better option to do this?
And second question: what's the best method to just extract version information from another assembly? But I guess that one has asked before and I can find an answer to this myself. (Something with reflection, GetExecutingAssembly and some more stuff.)
IEnumerable<String> GetLoadedAssemblies() {
foreach (var assembly in AppDomain.CurrentDomain.GetAssemblies()) {
yield return assembly.ToString();
}
}
Gives you the name (including version number) of every assembly being used in the app domain.
mscorlib, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
System.Xml, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089
etc.
One possible gotcha with using this: if the website has just started then some of the assemblies you are interested in might not have been loaded into the AppDomain yet, as they're unlikely to be referenced by a special page with just this functionality on it. If you click around the site first to make sure everything is loaded it should work OK, but if you need something more robust you'd have to add some AppDomain.Load() statements to the above code.
You could also use the GetReferencedAssemblies() method of the Assembly class to get all of the assemblies referenced by your web application.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With