Apply Versioning to Features: A HowTo for SharePoint Developers

It's a well known fact that versioning webparts is a real pain in the butt. Big Jim in DC and I have been pondering, searching the Internet and discussing what are some good ways to version web parts and features.  Today we decided to do something about it and came up with a simple strategy.  Use pre-build events to call a script that writes a value to the AssemblyFileVersion attribute of  the assebmlyInfo.cs (sorry vb'ers your just going to have to modify the scripts on your own ).  Then with another script read that value from the assemblyInfo.cs and write it to the feature.xml.  The description attribute to be sepcific.  That way from the user interface you can see the version and time built.

 

Jim wrote the script to update the Assembly and it can be found here.

This is what my pre-build events look like:

CD "$(ProjectDir)UTILS"cscript /nologo UpdateAssemblyFileVersion.vbs"$(ProjectDir)properties\AssemblyInfo.cs"cscript /nologo UpdateFeatureDescriptionVersion.vbs "$(ProjectDir)TEMPLATE\FEATURES\$(SolutionName)\Feature.xml" "$(ProjectDir)properties\AssemblyInfo.cs"

 

The source below will read just about any attribute in the assemblyInfo.cs file and append it to the end of the description for the feature (the description attribute of feature.xml).  Mine looks like this "| AssemblyFileVersion: 1.0.62223.1901   Built: 10/23/2007 7:01:03 PM".  It's pretty easy to see where the variable assemblyInfo is being create and modify as you meet your needs.

' VBScript source code'------------------------------------------------------------------------------'--- UpdateFeatureDescriptionVersion.vbs'------------------------------------------------------------------------------'--- Author - Stacy Draper'--- Date - 2007.10.23'------------------------------------------------------------------------------'--- This updates the description attribute of the feature node found in '--- feature.xml with the information found in AssebmlyInfo.cs.'------------------------------------------------------------------------------Option ExplicitDim fileHeaderfileHeader = "UpdateAssemblyFileVersion.vbs :: "EnsureCommandLineArgumentExistsEnsureFileExists WScript.Arguments(0), "Feature.xml"EnsureFileExists WScript.Arguments(1), "AssemblyInfo.cs"UpdateFeatureXml WScript.Arguments(0), WScript.Arguments(1)Private Sub EnsureCommandLineArgumentExists()If WScript.Arguments.Count <> 2 ThenWScript.Echo fileHeader & "You must supply the path to the AssemblyInfo.cs and feature.xml files as arguments."WScript.Quit 1End IfEnd SubPrivate Sub EnsureFileExists(path, fileName)Dim fsoSet fso = CreateObject("Scripting.FileSystemObject")If Not fso.FileExists(path) ThenWScript.Echo fileHeader & fileName & " does not exist at the path provided -> " & pathWScript.Quit 1End IfSet fso = NothingEnd SubFunction UpdateFeatureXml(featurePath, assemblyInfoPath)Dim node, xmlDoc, description, newDescription, descParts, assemblyInfo, posPipe, iSet xmlDoc = CreateObject("Msxml2.DOMDocument.3.0")xmlDoc.async = FalsexmlDoc.Load featurePathIf (xmlDoc.parseError.errorCode <> 0) ThenDim myErrSet myErr = xmlDoc.parseErrorerrQuit "An error occured -> " & myErr.reasonElseSet node = xmlDoc.selectSingleNode("//Feature")if isNull(node) or (node is nothing) thenerrQuit "Missing Feature node in feature.xml "end ifdescription = node.getAttribute("Description")if isNull(description) or (len(trim(description)) = 0) thenerrQuit "Missing description attribute of Feature node in feature.xml "end ifassemblyInfo =""assemblyInfo =assemblyInfo & "AssemblyFileVersion: " & getAttribValue(assemblyInfoPath, "AssemblyFileVersion")assemblyInfo =assemblyInfo & " Built: " & Now()posPipe = inStr(description, "|")if isNull(posPipe) or posPipe = 0thennewDescription = description & " | " &assemblyInfoelsedescParts = Split(description, "|")if uBound(descParts) > 1 then newDescription = descParts(0) for i = 1 to uBound(descParts) - 1 newDescription = newDescription & "|" & descParts(i) nextelsenewDescription = descParts(0)end ifnewDescription = newDescription & "| " & assemblyInfoend ifnode.setAttribute "Description", newDescriptionxmlDoc.save(featurePath)End IfEnd Function function getAttribValue(path, attrib)Dim fso, f1, ts, sDim startAttrib, startAttribValue, endAttribValue, strAttribValueConst ForReading = 1Set fso = CreateObject("Scripting.FileSystemObject")Set ts = fso.OpenTextFile(path, ForReading)s = ts.ReadAllstartAttrib = inStr (s, attrib)if (isNull(startAttrib) or startAttrib = 0) then errQuit attrib & " doesn't exist in AssemblyInfo.cs "end ifstartAttribValue = startAttrib + len(attrib) + 2endAttribValue = inStr(startAttribValue, s, ")") -1if (isNull(endAttribValue) or endAttribValue = 0) thenerrQuit attrib & " didn't end as expected in AssemblyInfo.cs "end ifstrAttribValue = mid(s, startAttribValue, endAttribValue - startAttribValue)getAttribValue = strAttribValuets.CloseSet ts = nothingSet fso = nothingend function function errQuit(message)WScript.Echo fileHeader & messageWScript.EchoWScript.Quit 1end function

 

#1 sharepointGuy on 8.04.2008 at 3:39 AM

good stuff thanks

#2 hermesoutletuk on 2.22.2012 at 9:14 PM

<a href="http://www.hermesoutletuk.com/">hermes outlet</a>If you can be a locater of the latest discoveries and in almost all the bag, you can easily browse journal, each often.<a href="http://www.hermesoutletuk.com/">hermes outlet online</a> You will leave her function area, will deposit, and at the same time processing Birkin Hector dense and hermes brought through the drive occasion need to keep your vision on your way, whatever their health. But when you should put the network world a little wide, is often unnecessary macho-ness provide brand-new elegant balance rival. <a href="http://www.hermesoutletuk.com/hermes-necklace-c-58.html">Hermes Necklace</a>If you are in the complex and unique gem ring help gift of the one you love, then you really should see your wise choice in the marquise diamond jewelry sales.<a href="http://www.hermesoutletuk.com/hermes-bracelets-c-56.html">Hermes Bracelets</a> Once we see these types of web site, you can't catch messenger bag again hermes by buying different objects. <a href="http://www.hermesoutletuk.com/hermes-bracelets-c-56.html">Hermes Bracelets</a>Provide hermes fashion place is not going to use the invention of the different stainless steel clothing in the different Louis vuitton brand name and Prada plus is the pressure in the carrier the leather.<a href="http://www.hermesoutletuk.com/hermes-bracelets-c-56.html">Hermes Jewelry</a>

Leave a Comment