A Failsafe For non-Debug TDS Builds

Thu Sep 15 2011

Another advantage of Team Development for Sitecore is that deployment to your various environments can be configured as part of the Solution’s Build Configurations, allowing you to easily deploy either right from your desktop or as part of an automated build process. The side effect of this is that if you don’t remember switching to say, your QA server’s build configuration, you can easily deploy in-progress code to an environment that’s not your local machine. (I will not confirm nor disconfirm I’ve done this.) Though you probably don’t want your production environment fully configured in TDS anyway, even a deploy to a QA or UAT server would be enough to get someone knocking on your door asking why “everything is broken.”

We put together a quick failsafe to prevent this. You’ll need to install the MSBuild Extension Pack. The example below assumes v4.0, x86. If the build is running in Visual Studio, and is anything other than a Debug build, a confirmation dialog appears that requires you to type in a super secret password before the build will continue. To add to your build, unload your TDS project, edit the .csproj, and paste in, perhaps near the bottom of the project config.

    <Import Project=”$(MSBuildExtensionsPath)\ExtensionPack\4.0\MSBuild.ExtensionPack.tasks” />
    <Target Name=“BeforeSitecoreBuild”>
        <CallTarget Targets=“ConfirmNonDebugBuild” Condition=”’$(BuildingInsideVisualStudio)’ == ‘true’ And ’$(Configuration)’ != ‘Debug’“/>
    <Target Name=“ConfirmNonDebugBuild”>
        <MSBuild.ExtensionPack.UI.Dialog TaskAction=“Prompt” Title=“Confirm Build” Button2Text=“Cancel” Text=“Type ‘whiskey’ below to confirm build to $(Configuration)”>
            <Output TaskParameter=“ButtonClickedText” PropertyName=“Clicked”/>
            <Output TaskParameter=“UserText” PropertyName=“Typed”/>
        <Message Text=“Button Text: $(Clicked) / Text: $(Typed)” Importance=“high”/>
        <Error Condition=”$(Clicked) == ‘Cancel’ Or $(Typed) != ‘whiskey’“/>

Nick Wesselman

Nick Wesselman started working professionally in software development just a few days after everyone realized we dodged a bullet with the Y2k bug. He’s worked as a Sitecore solution partner, Technology partner, and now for Sitecore itself. He lives with his wife, son, and daughter in Asheville, NC.