简体   繁体   English

web.config通过TFS 2015 Release Management进行更改

[英]web.config changes via TFS 2015 Release Management

In the past I've using web.config transforms when manually deploying code to set environment specific setting values and attributes. 在过去,我在手动部署代码以设置特定于环境的设置值和属性时使用web.config转换。 I am transitioning from environment specific manual builds to a single TFS 2015 Build deployed to multiple environments via Release Management. 我正在从特定于环境的手动构建过渡到通过发布管理部署到多个环境的单个TFS 2015 Build。 Environment specfic application settings values configured in the web.config are tokenized. web.config中配置的环境特定应用程序设置值是标记化的。 This method essentially inserts tokens into setting values during the build process. 此方法实际上在构建过程中将标记插入到设置值中。 When deployed the tokens are replaced with matching Release definition configuration values. 部署时,令牌将替换为匹配的发行版定义配置值。

This method is insufficient setting attributes of non-settings however. 但是,此方法不足以设置非设置属性。 Examples of these transforms include: 这些转换的例子包括:

<httpCookies requireSSL="true" xdt:Transform="Insert" />
<compilation xdt:Transform="RemoveAttributes(debug)" />
<httpRuntime xdt:Transform="RemoveAttributes(executionTimeout,maxRequestLength,useFullyQualifiedRedirectUrl,minFreeThreads,minLocalRequestFreeThreads,appRequestQueueLimit,enableVersionHeader)"/>
<httpRuntime enableVersionHeader="false" maxRequestLength="12288" xdt:Transform="SetAttributes"/>
<customErrors mode="On" xdt:Transform="SetAttributes"/>

What is the best way to update these attributes during release? 在发布期间更新这些属性的最佳方法是什么?

Both Web Deploy's parameters.xml method and transforms can be used with Release Management. Web Deploy的parameters.xml方法和转换都可以与Release Management一起使用。 Transforms would be triggered from Build and the process of replacing tokens created by a publish would be triggered by Release Management. 将从Build触发转换,并且发布管理将触发由发布创建的替换令牌的过程。

To trigger transforms during the build, you can do this one of two ways: 要在构建期间触发转换,您可以使用以下两种方法之一:

  1. Add the following MSBuild parameters to force the transformation to happen during the build 添加以下MSBuild参数以强制在构建期间进行转换

    /p:UseWPP_CopyWebApplication=true /p:PipelineDependsOnBuild=false

  2. Create a publish profile using the MSDeploy Package option and then trigger the packaging in Build using the following MSBuild parameters: 使用MSDeploy Package选项创建发布配置文件,然后使用以下MSBuild参数在Build中触发打包:

    /p:DeployOnBuild=true /p:PublishProfile=[nameOfProfile]

Either of the above methods will cause normal Web.config XDT's to run. 上述任一方法都将导致正常的Web.config XDT运行。 If you need other XML files to be transformed, you'll need to first install SlowCheetah . 如果您需要转换其他XML文件,则需要先安装SlowCheetah

Token Replace and Parameters 令牌替换和参数

Now that you have a build artifact with XDT's run, you can use token replacement and the WinRM tasks from Release Management. 既然您有一个运行XDT的构建工件,您可以使用令牌替换和Release Management中的WinRM任务 These will take the Web Deploy package from the Build and execute the SetParameters command before deploying it. 这些将从Build获取Web Deploy包并在部署之前执行SetParameters命令。 The trick is to take the SetParameters.xml file and run a token replace on it first, swapping out Release environment variables first. 诀窍是获取SetParameters.xml文件并首先在其上运行令牌替换,首先交换Release环境变量。

User Sumo gave a proper answer, but I want to record some comments related to what instead of how . 用户Sumo给出了正确的答案,但我想记录一些与什么有关的评论,而不是如何

IMHO there are different categories of settings to consider, let's exemplify. 恕我直言,有不同类别的设置需要考虑,让我们举例说明。 The database connection string changes at each environment, while requiring SSL should be turned on for all testing and production environments. 数据库连接字符串在每个环境中都会更改,同时应为所有测试和生产环境启用SSL。 In this perspective, you should have settings applied as early as possible, traditionally at build time and called Debug/Release builds; 从这个角度来看,您应该尽早应用设置,传统上在构建时应用,并称为调试/发布版本; and last-minute settings, environment dependent, up to runtime settings, like Feature toggles. 和最后一分钟设置,环境相关,直到运行时设置,如功能切换。

So in my view you can use a single tool or multiple tools, but it is important that you properly categorize your settings accordingly. 因此,在我看来,您可以使用单个工具或多个工具,但重要的是要相应地对设置进行适当的分类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM