繁体   English   中英

如何在VSTS发布管道中修改应用程序清单?

[英]How to modify the application manifest in VSTS release pipeline?

部署到集群时,我必须向应用程序清单xml文件添加其他参数。 在VSTS中配置了一个发布管道,我必须向其中添加任务。

如何实现呢? 我是否必须使用Powershell内联脚本? 如果是这样,如何修改工件目录中的文件?

@Karthick,谢谢您的回答,但是在保存xml时遇到了问题。 我确实将工作文件夹设置为 $(build.artifactstagingdirectory)

$appManifestFile = $(build.artifactstagingdirectory)\pkg\ApplicationManifest.xml
$xml = (Get-Content $appManifestFile) -as [Xml]
$newNode = $xml.CreateElement("Parameter")
$newNode.SetAttribute("Name","Test")
$newNode.SetAttribute("Value","Test")
Write-Host $newNode
$xml.ApplicationManifest.Parameters.AppendChild($newNode)
$xml.Save($appManifestFile)

如您所见,我直接从工件访问文件,然后对其进行修改。 该脚本在本地运行良好,但是在管道中文件保持不变。 我错过了什么吗?

您可以使用构建事件来执行此操作: 如何:指定构建事件(C#)

要么

如果您希望对VSTS构建管道执行相同的操作,则可以逐步添加Powershell Buid

1.获取到工件放置位置的路径

在此处输入图片说明

2.路径传递到您的Power Shell脚本

在此处输入图片说明

在此处输入图片说明

确保将工作目录设置为工件放置位置。 这是执行PowerShell脚本的地方

  1. 您需要将目录作为变量传递给PowerShell脚本,这里是“ appManifestFile”

    在此处输入图片说明

  2. PowerShell脚本添加带有'$ appManifestFile'为var的追加节点
 param ( [string]$appManifestFile = "" ) $appManifestFile = $appManifestFile + "\\app.manifest" echo "the path is set to : $appManifestFile" $xml = (Get-Content $appManifestFile) -as [Xml] $newNode = $xml.CreateElement("Parameter") $newNode.SetAttribute("Name","Test") $newNode.SetAttribute("Value","Test") $xml.DocumentElement.AppendChild($newNode) $xml.Save($appManifestFile) 

暂无
暂无

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

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