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.
I've been playing around with creating my own Build Tasks for Visual Studio 2005 and more specifically Web Deployment Projects.
In the course of playing around I've written some tasks (which I'll share with you all very soon) that hook into the Red Gate Sql Compare and Sql Data Compare products to deploy all my local SQL Server Schema and Data changes to the Development/Staging server when I deploy my applications. I've in effect created a "ClickOnce" ASP.NET deployment, which is pretty damn cool.
Here's a quick snippet of the Build Tasks in my wdproj file.
66 <Target Name="AfterBuild">
67
68 <!-- Syncronize the database schema between the local machine and the staging server --> 69 <RedGateSyncronizeSchema OriginDatabase="TestDatabase" OriginServer="MyMachine" OriginUsername="TestUser" OriginPassword="test" TargetDatabase="TestDatabase" TargetServer="StagingServer" TargetUsername="TestUser" TargetPassword="test" />
70 <RedGateSyncronizeData OriginDatabase="TestDatabase" OriginServer="MyMachine" OriginUsername="TestUser" OriginPassword="test" TargetDatabase="TestDatabase" TargetServer="StagingServer" TargetUsername="TestUser" TargetPassword="test" />
71
72 </Target> I'll follow up shortly with a full article (probably two) documenting my adventure and the code I've put together.
Just got a new Monitor for home, it's a Dell 20" Widescreen monster.
It's like having a whole new PC !