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

孤人 提交于 2021-02-07 14:54:56

问题


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

回答1:


First, with XML file transformation, the xx..config file is required. Secondly, the transform will be applied when publish web app to web deploy package or publish to server directly per to the configuration (e.g. Release, Debug).

Regarding web deploy package, there is xx.SetParameters.xml file, which contains the related transformed elements and the value will be applied during deploy. You can update that file before deploy.

Web.config Transformation Syntax for Web Project Deployment Using Visual Studio

Update:

You also can store the files in Secure Files, then copy the file to related folder through Copy file task:

  1. Download Secure File task
  2. Copy file task (Source folder: $(agent.builddirectory)\..\_temp)



回答2:


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.



来源:https://stackoverflow.com/questions/50946562/how-avoid-environment-config-transformations-being-deployed-on-server

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!