Display the version of all assemblies in an ASP.NET application on a page
More often than not it's quite useful to know if a Web site is running the latest version of assemblies, especially if you have shared common code which is updated regularly.
| Name | Version |
| App_Code.pacsdi-w | 1.0.0.42746 |
| Ajax | 5.7.25.1 |
| CustomProviders | 1.0.0.0 |
This snippet of code will print out a table of all (relevant - it excludes .NET assemblies or anything with no version) assembly versions to the page. (Yes the code is crude, I just like Olde Worlde Response.Write-esque code!) 1 this.Controls.Add(new LiteralControl("<table border=1 width=50%><tr><td>Name</td><td>Version</td></tr>"));
2 Assembly[] assemblies = AppDomain.CurrentDomain.GetAssemblies();
3
4 foreach (Assembly a in assemblies)
5 {
6 //Ignore the Framework Assembly's
7 string ExcludedNames = ("SystemMicrosoft.JScriptVJSharpCodeProviderCppCodeProviderWebDev.WebHostmscorlib");
8 if ((a.GetName().Name.ToString().IndexOf("System") < 0) && (a.GetName().Name.ToString().IndexOf("Microsoft") < 0) && (ExcludedNames.IndexOf(a.GetName().Name.ToString()) < 0) && (a.GetName().Version.ToString() != "0.0.0.0"))
9 {
10
11 try
12 {
13 string Version = a.GetName().Version.ToString();
14 AssemblyInformationalVersionAttribute[] infoversion = (AssemblyInformationalVersionAttribute[])a.GetCustomAttributes(typeof(AssemblyInformationalVersionAttribute), false);
15 if (infoversion.Length == 1)
16 {
17 Version += (" (" + infoversion[0].InformationalVersion.ToString() + ")");
18 }
19 LiteralControl lit = new LiteralControl();
20 lit.Text = "<tr><td>" + a.GetName().Name.ToString() + "</td><td>" + Version + "</td></tr>";
21
22 this.Controls.Add(lit);
23 }
24 catch
25 {
26 }
27
28 }
29 }
30 this.Controls.Add(new LiteralControl("</table>"));
If you're using ASP.NET 2.0 this can produce some "odd" looking results because of the new compilation engine. One way to avoid these results is to use the aspnet_merge tool which ships with the Visual Studio 2005 Web Deployment Projects plugin for Visual Studio.