Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How avoid *.<Environment>.config transformations being deployed on server

I'm using VSTS to deploy at several environments. And as usual, some parameters on config files need to be different depending the environment, hence I will use config transformations to deploy it at the target environment.

Since I want to have the package with both the config and the transform that will be applied later I set the Build Action as Content as such:

<Content Include="App_Config\MyConfig.config" />
<Compile Include="App_Config\MyConfig.prod.config">
  <DependentUpon>MyConfig.config</DependentUpon>
</Compile>
<Compile Include="App_Config\MyConfig.uat.config">
  <DependentUpon>MyConfig.config</DependentUpon>
</Compile>
<Compile Include="App_Config\MyConfig.dev.config">
  <DependentUpon>MyConfig.config</DependentUpon>
</Compile>

The package is done correctly and the deploy as well (MyConfig.config has the parameters changed depending on the environment it runs). My problem is that on the server machine I have the MyConfig.*.config files as well.

Looking at the official documentation example note's (https://docs.microsoft.com/en-us/vsts/pipelines/tasks/transforms-variable-substitution?view=vsts#xml-transformation-example) doesn't give anything clear. It's just "msbuild will do it before packaging and azure not" but doesn't explain a way to do it.

Edit: Solution I went with.

Basically I couldn't avoid to keep the artifacts clean, as they are not dependant on the environment. So after all Release pipeline I added a Delete files job (https://docs.microsoft.com/en-us/vsts/pipelines/tasks/utility/delete-files?view=vsts) To remove all configuration files with the following parameters:

Source Folder:
    $(wwwRoot)\

Contents:
    **\*.Debug.config
    **\*.Release.config
    **\*.UAT.config
    **\*.PROD.config
like image 729
OriolBG Avatar asked Jun 20 '18 10:06

OriolBG


People also ask

What is a config transform?

A Web. config transformation file contains XML markup that specifies how to change the Web. config file when it is deployed. You can specify different changes for specific build configurations and for specific publish profiles.

How do I create a new transformation in web config?

If you have a web application project, Right-click on web. config and choose Add Config Transform. This will add any config transforms that are missing from your project based on build configurations (i.e. if you have Production and Staging build configs, both will get a transform added).


1 Answers

You would probably need to think about creating a post deploy script to clean those files and add it to your release script to run at the end of deployment.

like image 156
Satish Avatar answered Oct 04 '22 21:10

Satish