Firstly building buildscripts for Team Systems are more like responding to events that gets fired by the Team System build engine, than writing the flow yourself. Which events get fired and which order they fire in can be found here.
Also - the start of building buildscripts with Team System is a wizard, which is nice but all that it's really doing is generating the stub for the MSBuild-script-file for you. If you want to tweak it (and you want) you'll have to code in the "scary" MSBuild/XML-langauge.
And finally the Team System doesn't come with loads of new functionality for MSBuild. So i still cast my vote on the MSBuild Community Task for anything slightly out of the box. They can be found and downloaded here.
I also got confirmed from Microsoft that ClickOnce-handling and versioning is not supported with the tasks included in Team System. Microsoft recommended me to use the MSBuild Community Tasks.
So - now to my buildscript. What we wanted to do was fairly simple (we thought); we just wanted to build the application and then perform a ClickOnce-publish to a certain location, in such a way that the latest version of the application automatically would be downloaded for any user accessing it.
This is how i did it:
First i created an itemgroup (called ClickOnceProjects) with parameters for the ClickOnce-deployment. This item group could be repeted for all projects that is to be published with ClickOnce.
<DeploymentThumbPrint>$(SolutionRoot)\$(ProjectNamespace).UI.Win\$(ProjectNamespace).UI.Win_TemporaryKey.pfx</DeploymentThumbPrint> <DeploymentPublishProperties> Configuration=Release;ProductName=App;PublisherName=Us; GenerateManifests=true;WebPage=default.htm</DeploymentPublishProperties>
On the AfterGet-target (which gets called by the TeamSystem-build-engine when the sourcefiles are retrieved from SourceControl) i do the following:
- Check out Version.txt which is a file with the versionnumber
- Check out Soulution.vb. This is a AssemblyInfo-file that is shared (linked-in) in all the projects of our solution. In this way we can get the same versionnumber for all our assemblies.
- Update the Versionnumber by incrementing the revsionnumber with one. For this we used the <Version>-task from MSBuild Community Task like:
<Version VersionFile="$(SolutionRoot)\SolutionItems\Version.txt" RevisionType="Increment">
<Output TaskParameter="Major" PropertyName="Major" />
<Output TaskParameter="Minor" PropertyName="Minor" />
<Output TaskParameter="Build" PropertyName="Build" />
<Output TaskParameter="Revision" PropertyName="Revision" />
<Message Text="New version: $(Major).$(Minor).$(Build).$(Revision)"/>
- Then the SolutionInfo.vb gets deleted and recreated with the new verion number by using the AssemblyInfo-task like:
<!-- Recreate SolutionInfo.vb -->
<Message Text="SYSTEM_NAME: Recreating Solution.vb"/>
AssemblyCopyright="Copyright © Company 2007"
Now the Team System build engine will go about and do it's stuff compiling etc. But then on the AfterDropBuild-target (when the executables is dropped to the build location) i publish the ClickOnce-applications (specified in the itemgroup above) as follows:
- Clean the content of the publish-location so that only the latest version of the build is available:
<RemoveDir Directories="$(ClickOnceDropLocation)" />
<MakeDir Directories="$(ClickOnceDropLocation)" />
- Then do a MSBuild-publish. This creates variables/output that contains the files for the ClickOnce-deployment. All important for this task to execute sucessfully is that you controll the versionnumber (which we do as shown above).
The task is executed as follows:
<MSBuild Targets="Publish" Projects="@(ClickOnceProjects)"
Properties="%(ClickOnceProjects.ProjectPublishProperties);%(ClickOnceProjects.DeploymentPublishProperties); PublishUrl=%(ClickOnceProjects.DeploymentFolderClient); MinimumRequiredVersion=$(Major).$(Minor).$(Build).$(Revision); ApplicationVersion=$(Major).$(Minor).$(Build).$(Revision)">
<Output TaskParameter="TargetOutputs" ItemName="PublishTargetOutputs"/>
- The output of this target is then moved to the publish-location like so:
<Output TaskParameter="Include" ItemName="FilesToPublish"/>
<!--Copy the publication-files to the server-->
Then of course we check-in the Version.txt and the SolutionInfo.vb on a successful build (as the last part of the AfterDropBuild-target) and do undo check-out on it on a failure (the
This is how we got the Gods of ClickOnce, MSBuild and Team System to work together in wonderful harmony. I am sure that this is only one of many ways you can do this, but this is one way and it works.
I realize that this can be hard to read and understand so please don't hesitate to contact me for the build-script-file or more information.
Published byon Last updated