Config transformation with Webdeploy, Preview not working

187 Views Asked by At

I want to use config transformation for custom files, if I replace ??? with MSDeployPublish, the Preview functionality is not working and it replaces the local files in solution. However the publish works without using Preview keeping local files untouched.

Config files:

AppSettings.config  
└AppSettings.Test.config  
└AppSettings.Stage.config  
└AppSettings.Release.config  
ConnectionString.config  
└ConnectionString.Test.config  
└ConnectionString.Stage.config  
└ConnectionString.Release.config  

What is the correct name of the target to use transformation for preview (without changing the files in soulution)? The way that web.config works when making preview with webDeploy

<Target Name="???">
   <TransformXml Source="App_Config\AppSettings.config" Destination="App_Config\AppSettings.config" Transform="App_Config\AppSettings.$(Configuration).config" />
    <TransformXml Source="App_Config\ConnectionStrings.config" Destination="App_Config\ConnectionStrings.config" Transform="App_Config\ConnectionStrings.$(Configuration).config" />
</Target>

I don't want to use any extensions like SlowCheetah, just build in functionalities.

<Target Name="Build"> also works

UPDATE 1

I've succeeded to publish without change local config files:

Destination="$(_PackageTempDir)\App_Config\ConnectionStrings.config"

But the Preview still not transforming the configs (also when I define a message for output it is not appear). What black magic happens when I click "Preview", in the publish screen ?

I've tried with targets: TransformWebConfigCore,CopyAllFilesToSingleFolderForPackage ,GatherAllFilesToPublish

1

There are 1 best solutions below

1
On BEST ANSWER

I've made it.

The Target name should be a custom name that doesn't exist. Then AfterTargets attribute should be specified with value of Package. This target happens almost at the end of the chain and ensures that the $(_PackageTempDir) directory is created.

The transformations are done in the package directory. This way ensures when making a preview with webdeploy it will compare files correctly and without change local files in source control.

Here is the definition:

<Target Name="CustomConfigTransform" AfterTargets="Package">
  <TransformXml Source="App_Config\AppSettings.config" Destination="$(_PackageTempDir)\App_Config\AppSettings.config" Transform="App_Config\AppSettings.$(Configuration).config" />
  <TransformXml Source="App_Config\ConnectionStrings.config" Destination="$(_PackageTempDir)\App_Config\ConnectionStrings.config" Transform="App_Config\ConnectionStrings.$(Configuration).config" />
</Target>

Of course there could be a better way: in the target CollectWebConfigsToTransform from Microsoft.Web.Publishing.targets, it should know somehow that there are more config files for transform. But currently no idea.