Sandcastle and Powershell

By | 2010-01-13

We have been using Sandcastle and the Sandcastle help file builder tools for our code documentation for quite some time now. One thing kept bugging me, the fact I had to edit the shfbproj file everytime we added or removed a project to the solution.

Since we use powershell over at the build server to do extra tasks around building and packageging, I wrote a little powershell script to generate (part of) the shfbproj file.

First we need to modify the shfbproj file to include a reference to an environment variable were we will store the assemblies to generate documentation for:

<DocumentationSources>$(DOCUMENTSOURCES)</DocumentationSources>

The thing to note here is the $(DOCUMENTSOURCES) which is going to be replaced with the content of environment variable DOCUMENTSOURCES by MsBuild.

Next we will generate this $(DOCUMENTSOURCES) through our powershell, which will put a piece of XML in this variable which contains all the documentsources:

foreach ($folder in get-Childitem | where {$_.PsIsContainer}) {
    cd $folder.name
    if (Test-Path "manifest.ddf" ) {
        cd bin
        $dll = $folder.name
        $dll += ".dll"
        $xml = $folder.name
        $xml+= ".xml"
        if (Test-Path $dll ){
            $documentsources += "<DocumentationSource sourceFile="".."
            $documentsources += $folder.name
            $documentsources += "bin"
            $documentsources += $dll
            $documentsources += """ />"
        }       
        if (Test-Path $xml ){
            $documentsources += "<DocumentationSource sourceFile="".."
            $documentsources += $folder.name
            $documentsources += "bin"
            $documentsources += $xml
            $documentsources += """ />"
        }       
        cd ..   
    }
    cd ..
}
cd $deploymentpath
$env:documentsources = $documentsources

And now all projects ( in this case that have a manifest.ddf ( SP2007 ) ) will be used for generating the documentation.

Leave a Reply

Your email address will not be published. Required fields are marked *