读取JSON中的XML值
我有一个json文件和一个xml文件。在xml文件中,我有一个元素,publisher name根下的name,并在json文件中读取该元素的值。如何实现这个场景 JSON文件读取JSON中的XML值,json,tfs,azure-devops,Json,Tfs,Azure Devops,我有一个json文件和一个xml文件。在xml文件中,我有一个元素,publisher name根下的name,并在json文件中读取该元素的值。如何实现这个场景 JSON文件 { "manifestVersion": 1, "id": "build-my-json", "version": "0.6.4", "name": "Build Extension", "description": "Integrate", "publisher":
{
"manifestVersion": 1,
"id": "build-my-json",
"version": "0.6.4",
"name": "Build Extension",
"description": "Integrate",
"publisher": "name"
}
XML文件
<?xml version="1.0" encoding="UTF-8"?>
</publishername>
<name>Nitin</name>
</publishername>
尼汀
基本上,我想为TFS扩展动态命名发布服务器名称。我假设您是通过生成发布扩展,您可以添加PowerShell任务,以根据更新发布服务器到XML文件: PowerShell脚本:
param(
[string]$xmlfile,
[string]$jsonfile
)
$xml = [xml](Get-Content $xmlfile)
$publisher=$xml.publishername.name
Write-Output $publisher
$a = Get-Content $jsonfile -raw | ConvertFrom-Json
$a.publisher=$publisher
$a | ConvertTo-Json | set-content $jsonfile
参数:-xmlfile[xml file]-jsonfile[json file]
更新:
不支持在扩展发布时间内更新发布服务器。我建议您通过build/release发布扩展。谢谢@strain MSFT我不发布build中的任何扩展我发布我的VSTS扩展,我只想通过xml文件更改我的发布者名称runtime@NitinParashar在发布运行时?@strain MSFTyes@NitinParashar不支持。(我更新了我的答案)@NitinParashar我建议您通过构建/发布发布扩展。