Google Website Translator Gadget

Tuesday 02 April 2013

Automatically Generate TFS Release Notes to PDF

Background

At Pragma we've been improving on some of our deployment practices during the past few releases.  I've always been a great proponent of trying to automate as much of the deployment process as possible.  One of the aspects that we improved on recently was the ability to automatically generate the Release Notes from our Team Foundation Server repository with every daily build of our software. This automation gives us quite a few benefits:
  1. Visibility into what's included with every build from the beginning of a release
  2. Ability to QA the Release Notes earlier in the development cycle as part of our daily builds
  3. Use of our existing TFS work items as the source for feedback, i.e. no context is lost between developers telling the technical writer what to include in the Release Notes.  The technical writer only needs to check the grammar and spelling of the TFS Work Item feedback.
  4. No manual intervention required to get the bulk of the Release Notes document generated
After doing some research on the web and looking at solutions like TFSChangeLog and this CodeProject article, we decided to roll our own due to some unique requirements within our environment.  The solution turned out to work quite elegantly and I hope this blog post will provide some pointers for other folks on  how to go about implementing something similar for their own environments.

Requirements

Here is a run-down of some of our requirements:
  1. We want to be able to merge some manually authored content into the Release Notes document.  Sections like What's New, Modifications and Maintenance typically contain functionality that are implemented by various TFS Work Items (Product Backlog Items, Tasks etc).  So we wanted the ability to manually author these sections and merge the content with remainder of the document that is automatically generated.
  2. We want the ability to selectively filter out some Work Items from being included in the Release Notes document by running a custom TFS Query.  An example of Work Items that we want to exclude are the internal bugs that were discovered for new functionality not yet released into production. 
  3. We want to use MS Word to author the manual content to make use of our existing corporate stylesheets
  4. We want the output to be available as a PDF
  5. We want command line support to allow us to automate the process as part of our daily builds using TeamCity
  6. We want the PDF to use bookmarks to enable easy navigation between the different sections
  7. We want the PDF to use our corporate branding/style
With the list of requirements,  we set out to build a solution to satisfy all of these.

Solution

Setting up a Word template to satisfy requirement #1 and #3 was a snap to do.  As we want the final output to be available as PDF, we save the Word document as a PDF once it has been updated.  To satisfy requirement #2 we created a TFS Query with the relevant query conditions to filter out unwanted Work Items. 

With the manually created PDF and the TFS Query returning the list of work items to use, we started looking at some code for generating a PDF from the Work Item contents.  We started off by creating a CommandLineOptions class to encapsulate all the different command line parameters to satisfy requirement #5:


The AppAction enumeration is used to indicate whether to run the app as a command line utility or to run the application using a GUI which allows you to manually specify the parameters to use for driving the report generation process - this is especially useful for testing purposes.  Just for reference, here is a quick view of the user interface:


The next step was to create a ReportRunner class to take these settings and generate the report in the PDF format:


Using the TFS API to programmatically query the contents of the work items was quite easy to do as illustrated through the ConnectToTfs and GenerateReleaseNoteWorkItem methods above.  With the Work Item information now processed and available in memory, the final step in the generation process was to take the list of processed work items, write them to a PDF file and finally merge the contents of this generated file with the output of the manually created PDF file.  This turned out to be quite an interesting exercise and by far the most challenging aspect of the whole solution :-)

Generating the PDF

After looking at various options for generating a PDF programmatically, we decided to use the C# open source port of the well-known Java iText library called iTextSharp.  Through reading various articles on the web (there is also this great Manning Book on the Java version), we eventually figured out how to generate, merge and create a PDF to satisfy the remainder of the requirements.

On a high level, the process for generating the PDF turned out as follows:
  1. Create new blank PDF
  2. Add a front page
  3. Add (merge) the contents of the manual PDF into the new blank PDF whilst keeping track of the bookmarks contained within the manual document (see Requirement #6)
  4. Run through the list of processed work items to add the document content for them into relevant sections in the new PDF
  5. Re-bookmark the whole document to enable easy navigation throughout the whole PDF in support of requirement #6.
This high-level process was implemented in the Publish method of the ReleaseNotesPdfWriter class.


To add the front page and also include a custom footer on every page containing the build version, generation time stamp as well as page number, we created a ReleaseNotesPdfPageEvents class to implement the IPdfPageEvent interface that iTextSharp provides for executing custom logic when a PDF document is opened/closed, new paragraphs, sections are added etc.  This class is then assigned to PageEvent of the PDF writer to ensure that the custom logic executes as part of the PDF generation process (see line 16).

After adding the front page, the content of the manual PDF is merged into the new document (lines 30-35). Keeping track of the bookmarks turned out to be quite an interesting exercise and is done as part of the Merge method.

After merging the existing content, we process the in-memory list of work item information by firstly grouping the Work Items based on their resolution types into sections like "How do I", "Bug Fixes" etc. (lines 38-41) and thereafter writing these sections into the document using the WriteWorkItems method:


For every new section we add an additional bookmark into the Bookmarks collection to make sure that we have a complete list of bookmarks for all the available sections in the document (see line 14).  The final step in the generation process is to add these bookmarks into the new document using the CreateBookmarks method.


Conclusion

Here is a screenshot of an example report generated for our latest release to give you an idea of what is possible using the solution described above.  I think you'll agree that the content looks quite professional.


I trust you find the above mentioned pointers useful in creating your own solution.

Friday 28 December 2012

Async support for running Silverlight Unit Tests

One of the great new features included with .NET 4.5 and Visual Studio 2012 is the async/await support for writing more elegant multi-threaded code in C# or Visual Basic.  Support for writing tests that make use of the async/await keywords is available for the Microsoft Test Framework as well as most of the other popular xUnit testing frameworks like NUnit.  In addition to providing support for async/await baked into the compilers for Visual Studio 2012 and .NET 4.5, Microsoft has also released the Async Targeting pack for Visual Studio 2012 that enables projects targeting .NET 4.0 or Silverlight 5 to use the Async language feature in C# and Visual Basic code.

Using it in your Silverlight 5 code is quite handy – especially when invoking web services from the client.  However, the Microsoft Test Framework for Silverlight has not been extended to support running these asynchronous tests.  However, in a recent blog post by Morten Nielsen he shows how it is possible to go about adding this support to the Silverlight Test Framework.  He provides a customized version of the Silverlight Test Framework, but also urges us to go vote for getting this added directly to the official Silverlight Toolkit

I know a lot of development shops like ourselves still have quite a substantial amount of Silverlight code to maintain, so please go and vote for the issue to get Microsoft to add support for it in the Silverlight Toolkit.

Monday 19 November 2012

FxCop Standalone for VS 2012, .NET 4.5 and Portable Libraries

In our current team environment we are using the VS 2012 Professional SKU with a MSDN subscription due to the cost savings it affords us.  That implies that we miss out on features like the integrated Code Analysis.  Up till VS 2010, Microsoft released an updated edition of the Code Analysis engine with the standalone FxCop installation.  That implied that even though we didn’t get the tooling integrated into Visual Studio directly, at least we could use the standalone edition of FxCop to execute the same set of Code Analysis rules on our code base - albeit in a bit more laborious fashion.

With VS 2012 Microsoft has not yet released an update to the standalone FxCop.  Here’s the MSDN forum post where I raised the issue as to when an update will be released.  The current standalone edition also doesn’t seem to support the new Portable Library format being used to cross target different .NET platforms.  Following the advise on the forum post I’ve created an UserVoice issue to request an update.  So if you are in the same boat as to using the standalone edition, please head over to UserVoice and go vote for the issue to get it resolved.  Thanks.

PS: Btw, if you would like to run the standalone FxCop in VS, you might want to consider the FxCop Integrator.  Haven’t used it, but it seems promising although there hasn’t been an update for a while.

Monday 16 April 2012

Practical Performance Profiling E-book

The folks at RedGate, makers of some quality .NET and SQL Server tools like Reflector, ANTS Memory and Performance Profiler, SQL Monitor (and much more) have published an excellent, free book on performance profilingPractical Performance Profiling by Jean-Philippe Gouigoux seems like a wonderful comprehensive guide for improving application performance by understanding performance bottlenecks from every possible angle.   Do yourself a favour and register to get your own copy soon.  Happy profiling Smile

Wednesday 08 February 2012

Silverlight 5 Upgrade Woes

We recently struggled to upgrade the UI of On Key, Pragma’s Enterprise Asset Management System (EAMS) to Silverlight 5.  We struggled with getting Silverlight 5 binaries for a lot of the open source projects (Moq, Castle.Core), but it was the lack of development tooling support in Visual Studio 2010 that really disappointed us.  I can understand that the open source projects are slack in providing support for Silverlight 5.  We solved the problem by getting the source code and creating Silverlight 5 binaries ourselves.  However our hands are cut off when it comes the development tooling in Visual Studio.  Expression Blend 5 is still only in preview edition with no word on when a final version that supports the SL 5 RTW will be provided.  Code Analysis (FxCop) and Code Metrics analysis are broken for Silverlight 5 projects.  I find it very disappointing that MS didn’t make sure that all parts of the development tooling surrounding Silverlight 5 was working by the time that Silverlight 5 went RTW.  Hopefully these issues will be resolved soon, but one sort of gets the impression that with no more momentum behind Silverlight it might take quite a while Sad smile