Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transforming files with msdeploy

Can I use the config transforms mechanism of MSDeploy to transform other files?

like image 742
Greg B Avatar asked Dec 16 '22 18:12

Greg B


2 Answers

(another approach)

The msdeploy packaging is jsut invoked during an MSbuild run for your project.

TransformXml is an included task of a .csproj or .vsproj build.

Just modify your build process to invoke that task on whatever file you need.

For example, what we do is write a custom target

<Target Name="TransformFile">

    <TransformXml Source="$(DestinationPath)\$(Sourcefile)" 
       Transform="$(DestinationPath)\$(TransformFile)" 
       Destination="$(DestinationPath)\$(DestFile)" />
    </Target>

Then modify your .csproj to run this BEFORE the Publish task is invoked.

<CallTarget Targets="TransformFile" 
   Condition="'$(CustomTransforms)'=='true'" />
like image 181
Taylor Bird Avatar answered Mar 29 '23 23:03

Taylor Bird


The answer by Taylor didn't work for me and he didn't provide further details. So I went spelunking into the Microsoft.Web.Publishing.targets file to find a solution. The following MSBuild Target can be added to project file to transform all other config files in the root application directory. Enjoy :)

<Target Name="TransformOtherConfigs" AfterTargets="CollectWebConfigsToTransform">
<ItemGroup>
    <WebConfigsToTransform Include="@(FilesForPackagingFromProject)"
                           Condition="'%(FilesForPackagingFromProject.Extension)'=='.config'"
                           Exclude="*.$(Configuration).config;$(ProjectConfigFileName)">
    <TransformFile>%(RelativeDir)%(Filename).$(Configuration).config</TransformFile>
    <TransformOriginalFile>$(TransformWebConfigIntermediateLocation)\original\%(DestinationRelativePath)</TransformOriginalFile>
    <TransformOutputFile>$(TransformWebConfigIntermediateLocation)\transformed\%(DestinationRelativePath)</TransformOutputFile>
    <TransformScope>$([System.IO.Path]::GetFullPath($(_PackageTempDir)\%(DestinationRelativePath)))</TransformScope>
  </WebConfigsToTransform>
  <WebConfigsToTransformOuputs Include="@(WebConfigsToTransform->'%(TransformOutputFile)')" />
</ItemGroup>
</Target>
like image 23
chief7 Avatar answered Mar 29 '23 23:03

chief7