Blog

Tracking solution version numbers


by Tobias Lekman, 15 January, 2009

I recently had a long discussion with a colleague regarding package versions when deploying SharePoint features. After some investigation, it seems that the SharePoint object model does not contain a version number for solution, only a time of last update.

But... if you use the CodePlex SharePoint Installer it registers a version number using the configuration property SolutionVersion.

 1: <?xml version="1.0" encoding="utf-8" ?>

 2: <configuration>

 3: <appSettings>

 4: <add key="BannerImage" value="Default"/>

 5: <add key="LogoImage" value="None"/>

 6: <add key="SolutionId" value="19D82049-1892-4d16-8E2B-FAF2327EDB99"/>

 7: <add key="SolutionFile" value="Sample.wsp"/>

 8: <add key="SolutionTitle" value="Sample"/>

 9: <add key="SolutionVersion" value="1.1.0.0"/>

 10: <add key="Require" value="MOSS" />

 11: <add key="UpgradeDescription" value="Upgrades {SolutionTitle} on all frontend web servers in the SharePoint farm."/>

 12: <add key="RequireDeploymentToCentralAdminWebApplication" value="true"/>

 13: <add key="RequireDeploymentToAllContentWebApplications" value="false"/>

 14: </appSettings>

 15: </configuration>


I then decided to extend the SharePoint Central Administration site screen "Solution Management" to show the version number.

First, add a server-side C# function within the file "Solutions.aspx" located within the folder C:\Program Files\Common Files\microsoft shared\Web Server Extensions\12\TEMPLATE\ADMIN.



 1: <script runat="server">

 2:  

 3: public string GetVersion(string solution)

 4: {

 5: try

 6:     {

 7:         Microsoft.SharePoint.Administration.SPFarm farm = Microsoft.SharePoint.Administration.SPFarm.Local;

 8: string key = "Solution_" + farm.Solutions[solution].Id.ToString() + "_Version";

 9: return farm.Properties[key].ToString();

 10:     }

 11: catch (System.NullReferenceException)

 12:     {

 13: return string.Empty;

 14:     }

 15: catch (Exception ex)

 16:     {

 17: return ex.ToString();

 18:     }

 19: }

 20:  

 21: </script>


Next, extend the SPGridView with a template column as:



 1: <asp:TemplateField

 2: HeaderText="Version">

 3: <ItemTemplate>

 4: <%#
 5: GetVersion(Eval("ItemName").ToString()) 
6:     %>

 7: </ItemTemplate>    

 8: </asp:TemplateField>


You will now have a version column containing the solution version numbers added by the CodePlex SharePoint Solution Installer.

solutions