Friday, September 9, 2011

Windows Azure Multi-Site Single Role Using Host Headers With Config Transforms

I was excited to find out that Azure supported multiple sites with a single worker role with a few simple configuration changes thanks to Wade Wegner's Example. I was a little disappointed that the process of building the package did not include the XDT transforms on the config. Neither is the website packaged for deployment which strips out all non essential files references in the web application before deploying. After a number of google searches and some trial and error I came up with the following solution:


In my example I created a single website and associated it to my azure project as the only worker role.

In the worker role pre-build event I have placed the following for each website that needed to be packaged and transformed:

Cloud Project Pre Build Event

rmdir ..\Deploy.Cloud\Website.Mvc /S /Q
"%systemroot%\Microsoft.NET\Framework64\v4.0.30319\MSBuild.exe" "$(ProjectDir)..\Website.Mvc\Website.Mvc.csproj" "/p:Platform=AnyCPU;PackageAsSingleFile=False;Configuration=$(ConfigurationName);DesktopBuildPackageLocation=..\Package\Website.Mvc;PackageAsSingleFile=False;IntermediateOutputPath=..\Deploy.Cloud\Website.Mvc\\" /t:Package

*You must remove the intermediate location before it creates the package otherwise debug/release configurations will not differ

*Note the extra slash at the end yes that is intentional if you do not add it you will get some interesting error messages about properties with no value

ServiceDefinition.csdef

<Site name="Website.Mvc" physicalDirectory="Website.Mvc\Package\PackageTmp">


What's going on here
Every time the cloud project builds it will copy and package the website in the cloud project's project root folder as the website name. Next step is to update the ServiceDefinition.csdef use the intermediate path location for the physicalDirectory. Why? because the package directory contains all of the assets to be deployed as a web deployment project which is not needed when deploying using a web role.


References