2012年9月20日

[Azure][ASP.Net]Publish to Azure with config transformation

* This only works for Web Roles with single APS.Net web site, if you have additional web project configured as a Virtual Application, you should first publish it to a folder other then your source code folder, then configure @physicalDictory of <VirtualApplication>ServiceDefinition.csdef point to that folder

Config transformation was first introduced in VS2010 and has become a very helpful feature when develop/deploy in various environment, however, this feature seem not works fine with Azure SDK when developing Cloud Services. You’ll find even if you’ve configured the transformation, it just doesn’t work when publish/package your Azure projects.

To fix that, we need to do some little modify on project files. First we are going to download and install a useful VS add-in SlowCheetah.

Once installed, let’s unload our Azure project file from solution. NOTE, unload Azure project, not the ASP.Net Web project.

image

Then edit project file.

image

Add the following codes to the project file

<Target Name="BeforeBuild">
<Copy SourceFiles="web.config" DestinationFiles="Web.Original.Config">
</Copy>
<TransformXml Source="Web.Original.Config"
Transform="Web.$(Configuration).config"
Destination="Web.Config"/>
</Target>


The updated file should look like this



image



Reload the project and verify it with your Azure publish.

沒有留言:

Blog Archive

About Me