TFS Build And Multiple Websites In One Web Role On Azure

Since the 1.3 sdk update, setting up multiple websites on a single web role is pretty straight forward. However, there is a little bit of a gotcha when using TFS build to compile and publish the packages.

The problem is that when you combine two or more website projects into a single role, the azure project still only compiles the primary website within the project. The other projects seem to just be copied from the location specified physicalDirectory attribute and included in the published package. Ensuring those are included in the package during the build process on your TFS Build server is fairly straight forward – you just add them in the ‘Items to Build’ of your build definition (before the cloud project!). However, what that does not do is transform the web.config files of those projects. The build seems to only compile the code and none of the extra tasks.

Discovering this took up two days of investigating – the problem manifested in a strange authentication cookie domain issue because our config transform should have replaced the authentication settings. Once we realised what was happening, fixing it did not take so long.

We add an after build event that transforms the config files in the project files but only if it looks like we are on the build server. Unload the website project in question and edit the .csproj file. Add an AfterBuild target as follows:

<Target Name="AfterBuild">
    <!-- other tasks may already be here -->
    <TransformXml Condition="Exists('$(OutDir)\_PublishedWebsites\$(TargetName)')"
                  Source="Web.config" Transform="$(ProjectConfigTransformFileName)"
                  Destination="$(OutDir)\_PublishedWebsites\$(TargetName)\Web.config" />
</Target>

What this does is run the transforms on the web.config files if the build server _PublishedWebsites directory exists.

The only thing lacking here is the file tidy up – the original config files still remain and are deployed in the package along with other files that are usually removed during the build. This does not effect the website in any way but it would be nice to remove those too. Any suggestions on how would be gratefully received.

 

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.