1
votes

We currently publish our web app vis MSDeploy, to create a .ZIP file (file deployment). I have some .config files that I want to apply transforms to when we publish. So I've created an appSettings.test.config and an appSettings.live.config.

To facilitate this, I have added this to the csproj of our web app, which applies the transforms:

<UsingTask TaskName="TransformXml" AssemblyFile="$(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v12.0\Web\Microsoft.Web.Publishing.Tasks.dll" />
  <Target Name="ApplyConfigTransforms" BeforeTargets="TransformWebConfigCore">
    <TransformXml Source="appSettings.config" Transform="appSettings.$(Configuration).config" Destination="appSettings.config" />
    <TransformXml Source="connectionStrings.config" Transform="connectionStrings.$(Configuration).config" Destination="connectionStrings.config" />
  </Target>

This hooks in to the TransformWebConfigCore target and does the work. BUT, it applies the transforms to the appSettings file in my web folder (as expected from the destination). What I want to do is apply the transform to the file in the output pacakge.

How can I do this? I don't know how to get a handle on the temporary folder that is created when you publish..

1

1 Answers

0
votes

Don't you just hate it when you find the answer yourself about 10 mins after posting.

I hacked the destination, which fixed the issue. Would be nice if I had this in a property, but I couldn't find one to use, so I did:

<Target Name="ApplyConfigTransforms" AfterTargets="CopyAllFilesToSingleFolderForMsdeploy">
    <TransformXml Source="appSettings.config" Transform="appSettings.$(Configuration).config" Destination="obj\Test\Package\PackageTmp\appSettings.config" />
    <TransformXml Source="connectionStrings.config" Transform="connectionStrings.$(Configuration).config" Destination="obj\Test\Package\PackageTmp\connectionStrings.config" />
  </Target>

Note, I also changed the target, to make sure it happens just after all my files have been copied