|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
AbstractI want to address two topics in this article, one educational and the other practical. My educational reason is to show you how to do something non-trivial utilizing the XML and XSL .NET Framework classes. In doing this I'm going to show you one approach to solving the practical problem of updating version numbers in automated nightly builds; in particular of C++ and C# projects. Because of the use of XSL the solution is open ended, so you can use for any language or project, with only a little extra work. Version ResourcesIf you've been a Microsoft Windows developer long enough, you've had to solve the problem of updating your binaries version numbers after each major build of your product. Incrementing the version number after each build gives you an excellent way to localize problems to particular builds. Also, having good version numbers is essential for your installer to be able to install over or alongside existing copies of your product. If you practice good software development principles and try and do a full build automatically every day, there's a good chance you'll have figured out some automated way to do the updates. If not, or if you are not happy with your existing solution, today is your lucky day! DetailsThe tool consists of a single executable called
An XML file with an extension PVD (for Product Version Data) contains all the
relevant version information for all the binary files in your
product. This file is the first input into MKVER2. You'll
also specify the name of the output file, in the diagram it's These templates are looked for in the following various locations in order (1)
the directory specified on the command line, (2) the directory specified by the Take a look at the format of a PVD file and you'll see it's pretty
straightforward. One thing that might take some explaining are the <VersionInfo lang="1033" charset="1200">
...
...
</VersionInfo>
The idea here is that all language specific pieces of version information, such
as copyrights, descriptions, trademarks, etc. are contained within these
elements. Using command line parameters you can determine which language
strings end up in your version resources. Take a look at the first part
of <?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform" version="1.0">
<xsl:output method="text" version="4.0" encoding="utf-8"/>
<xsl:param name="lang"/>
<xsl:param name="charset"/>
<xsl:param name="name"/>
<xsl:template match="/VersionData">
As you can see we make use of XSL parameters to pass this information into the
transform. Later on in the transform we use these parameters as input to
the XPath query that retrieves a specific <xsl:apply-templates select=
The try
{
inputFile = Path.GetFullPath((string)inputFile);
// load the version data
document.Load(inputFile);
// wrap it with an XmlNavigator
navigator = document.CreateNavigator();
if (!IsCorrectRevision(1))
return;
UpdateProductVersion();
// Add dynamically generated nodes
AddNodes();
if (trace)
{
XmlTextWriter xw = new XmlTextWriter(BpConsole.Out);
xw.Formatting = Formatting.Indented;
document.WriteContentTo(xw);
xw.Flush();
BpConsole.WriteLine();
}
TransformDocument();
}
catch (Exception e)
{
WriteMessage(MessageType.Error, e.Message);
}
First we grab the input document and load it into an What is the function of
In order that someone who doesn't have access to the source code can
easily see what these new elements are available, I added the The final step is to call Using the ToolHow do you use the tool? Well you you've noticed MKVER2 uses MKVER2 to do
it's own versioning! Included in the sample source code solution file are
a couple of Makefile projects. The one called One thing I've discovered about C# projects that I'm not thrilled about is that
there does not appear to be any way at all to do the equivalent of C++
includes. Unless you build from the command line you can't even have a C#
project in VS.NET that includes files in directories other than the project
directory. What this basically means is you'll have to go through
each project and update the version information separately. Note also
that this is why you have to specify a
Yes, I know that .NET projects can automatically create version numbers for
themselves, if you use an attribute like For C++ projects, you'll have things easier. You can create an You can also use MKVER2 to generate any other type of output you like containing the version information. I've include some XSL files for generating BAT and HTML files for your versioning pleasure. ConclusionOK, if you read this article to learn how to program in XSL or .NET your probably a bit disappointed by now. I suggest you store this article away for future reference. However, if you have already mastered the basics of XML and XSL and were looking for a power sample to really show you some of the things you can usefully do with it, you should be happier. I'm blown away by how easy it is to do XML related stuff in .NET. I've written a fair amount of MSXML code using the COM interfaces in the past, and I'm never going back! As far as the version utility goes, I hope it's useful to you. If someone writes XSL transforms for VB.NET, Java/J# or any other versionable project and sends them to me, I'd be happy to add them to the MKVER2 download on this page. Finally, if you haven't found it yet and you are looking for a knock your socks off application of XSL with the .NET Framework check out NDoc.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||