如何避免在服务器上部署*.< Environment> .config转换 [英] How avoid *.<Environment>.config transformations being deployed on server

查看:51
本文介绍了如何避免在服务器上部署*.< Environment> .config转换的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VSTS在多个环境中进行部署.而且像往常一样,配置文件上的某些参数需要根据环境而有所不同,因此我将使用配置转换将其部署在目标环境中.

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.

由于我希望同时包含配置和转换的软件包,因此我将Build Action设置为Content这样:

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>

该软件包正确完成,并且也进行了部署(MyConfig.config的参数根据其运行的环境而有所更改).我的问题是在服务器计算机上也有MyConfig.*.config文件.

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.

查看官方文档示例注释的( https://docs.microsoft.com/zh-cn/vsts/pipelines/tasks/transforms-variable-substitution?view=vsts#xml-transformation-example )不会"不要说清楚任何事情.只是"msbuild会在打包之前先做,天青不行",但没有说明这样做的方法.

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.

我使用的解决方案.

基本上,我无法避免保持工件整洁,因为它们不依赖于环境.因此,在所有版本发布管道之后,我添加了一个删除文件作业(

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

推荐答案

首先,通过XML文件转换,需要xx..config文件.其次,当根据配置(例如Release,Debug)将Web应用发布到Web部署程序包或直接发布到服务器时,将应用转换.

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).

关于Web部署程序包,有xx.SetParameters.xml文件,其中包含相关的转换后的元素,并且该值将在部署期间应用.您可以在部署之前更新该文件.

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项目的Web.config转换语法使用Visual Studio进行部署

更新:

您还可以将文件存储在保护文件,然后通过复制文件"任务将文件复制到相关文件夹:

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

  1. 下载安全文件任务
  2. 复制文件任务(源文件夹: $(agent.builddirectory)\ .. \ _ temp )

这篇关于如何避免在服务器上部署*.&lt; Environment&gt; .config转换的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆