【发布时间】:2020-07-09 22:25:40
【问题描述】:
我正在使用 FileTransform@2 任务在 Azure DevOps Pipeline (yaml) 中使用 web.[environment].config 转换 web.config。虽然我不确定为什么,但它似乎在导致整个工作失败的单个转换中失败了。
这是来自任务的错误消息:
Executing SetAttributes (transform line 72, 48)
on /configuration/appSettings/add[@key='PCWSUser']
System.NullReferenceException: Object reference not set to an instance of an object.
Applying to 'add' element (no source line info)
at Microsoft.Web.XmlTransform.XmlTransformationLogger.ConvertUriToFileName(XmlDocument xmlDocument)
Set 'key' attribute
at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogWarning(XmlNode referenceNode, String message, Object[] messageArgs)
Set 'value' attribute
at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes()
Set 2 attributes
Done executing SetAttributes
所以看起来它不喜欢 PCWSUser appSetting。
这是 PCWSUser 的 web.config sn-p:
...
<add key="PCWSUser" value="TheUserName" />
...
这是 PCWSUser 的 web.[environment].config(在本例中为 web.qa.config)sn-p:
...
<add key="PCWSUser" value="TheUserNameQA" xdt:Transform="SetAttributes" xdt:Locator="Match(key)"/>
...
我不太确定自己做错了什么......当转换在 Visual Studio 中本地完成时,它没有任何问题。另一个奇怪的事情是我已经运行了几次,它似乎每次都选择了不同的 appSetting 来出错。相同的错误消息和所有,只是不同的设置。所有设置都以这种方式设置仅供参考。
如果您需要更多信息,请告诉我。
编辑 1
根据@Kevin Lu-MSFT 的建议,我在构建步骤中添加了/p:TransformWebConfigEnabled=false 并再次尝试。
构建阶段日志:
##[debug]INPUT_MSBUILDARGS: '/t:rebuild /p:DeployOnBuild=true /p:PublishProfile="Dev" /p:PackageLocation="D:\agent\_work\283\a" /p:TransformWebConfigEnabled=false'
但是,尽管错误再次出现,但转换仍然失败。这次错误在两个步骤之间,所以我什至不清楚出了什么问题。
部署阶段日志:
Executing Replace (transform line 10, 105)
on /configuration/connectionStrings/add[@name='SqlConnectionString']
Applying to 'add' element (no source line info)
Replaced 'add' element
Done executing Replace
System.NullReferenceException: Object reference not set to an instance of an object.
at Microsoft.Web.XmlTransform.XmlTransformationLogger.ConvertUriToFileName(XmlDocument xmlDocument)
at Microsoft.Web.XmlTransform.XmlTransformationLogger.LogWarning(XmlNode referenceNode, String message, Object[] messageArgs)
at Microsoft.Web.XmlTransform.Transform.ApplyOnAllTargetNodes()
Executing Replace (transform line 11, 105)
on /configuration/connectionStrings/add[@name='DB2ConnectionString']
Applying to 'add' element (no source line info)
Replaced 'add' element
Done executing Replace
【问题讨论】:
-
你有这些值作为管道变量吗?
-
您可以参考答案中的故障排除步骤。您可以尝试直接在管道中运行任务以转换文件。如果没有帮助,您可以与我们分享构建定义。
-
@Crowcoder 它是一个混合体。我有实际的单独文件(在这种情况下为 web.config 和 web.qa.config),但连接字符串通过替换来自 Keyvault。替代似乎很好。 Keyvault 任务将它们作为变量注入到管道中。
标签: c# asp.net web-config azure-pipelines web.config-transform