概要
TFS online 自动编译时如何修改web.config
步骤
安装Release Management Utility tasks
https://marketplace.visualstudio.com/items?itemName=ms-devlabs.utilitytasks
将 Tokenizer 添加进BuildStep
http://blogs.blackmarble.co.uk/blogs/rfennell/post/2016/03/01/A-vNext-build-task-and-PowerShell-script-to-generate-release-notes-as-part-of-TFS-vNext-build
编写webConfigReplace.json,并提交到tfs
{ "default": { "CustomVariables": { "Variable1": "value1", "Variable2": "value2" }, "ConfigChanges": [ { "KeyName": "/configuration/metaModel", "Attribute":"configSource", "Value":"Config\\MetaModel.config" }, { "KeyName": "/configuration/connectionStrings", "Attribute": "configSource", "Value": "Config\\ConnectionStrings.config" } , { "KeyName": "/configuration/runtime/assemblyBinding/probing", "Attribute": "privatePath", "Value": "bin;binMP;binQF" } , { "KeyName": "/configuration/system.web/compilation", "Attribute":"debug", "Value":"false" } ] } }
注意:此处default为Environment name,若未配置Environment name,则指定default即可
配置Configuration Json filename: $(Build.Repository.LocalPath)/src/XXX/webConfigReplace.json
注意,此处必须使用$(Build.Repository.LocalPath)变量获取文件根路径。
另外,
1)若要使用_XXX_格式替换web.config 中的标记为变量,变量不支持系统内部变量,若要使用系统内置变量,如$(Build.SourceVersion)
可以新建一个用户变量,然后设置其值为$(Build.SourceVersion)
2)若config节点有namespace,则需要指定
{
"NamespaceUrl": "urn:schemas-microsoft-com:asm.v1",
"NamespacePrefix": "asm",
"KeyName": "/configuration/runtime/asm:assemblyBinding/asm:probing",
"Attribute": "privatePath",
"Value": "bin;binMP;binQF"
}