首页 文章

如何避免在服务器上部署* . <Environment> .config转换

提问于
浏览
1

我正在使用VSTS在多个环境中部署 . 和往常一样,配置文件的一些参数需要根据环境的不同而不同,因此我将使用配置转换在目标环境中部署它 .

由于我希望包含配置和稍后将应用的转换的包,我将Build Action设置为Content,如下所示:

<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文件 .

查看官方文档示例注释(https://docs.microsoft.com/en-us/vsts/pipelines/tasks/transforms-variable-substitution?view=vsts#xml-transformation-example)并没有't give anything clear. It'只是"msbuild will do it before packaging and azure not"但没有解释这样做的方法 .

Edit: Solution I went with.

基本上我无法避免保持工件清洁,因为它们不依赖于环境 . 因此,在所有Release管道之后,我添加了一个删除文件作业(https://docs.microsoft.com/en-us/vsts/pipelines/tasks/utility/delete-files?view=vsts)使用以下参数删除所有配置文件:

Source Folder:
    $(wwwRoot)\

Contents:
    **\*.Debug.config
    **\*.Release.config
    **\*.UAT.config
    **\*.PROD.config

2 回答

  • 0

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

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

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

    更新:

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

    • 下载安全文件任务

    • 复制文件任务(源文件夹: $(agent.builddirectory)\..\_temp

  • 0

    您可能需要考虑创建一个post deploy脚本来清理这些文件,并将其添加到您的发布脚本中,以便在部署结束时运行 .

相关问题