【问题标题】:Read XML value in JSON以 JSON 格式读取 XML 值
【发布时间】:2017-09-05 14:58:41
【问题描述】:

我有一个 json 文件和一个 xml 文件。在 xml 文件中,我有一个元素,名称位于发布者名称的根目录下,并在 json 文件中读取该元素的值。如何实现这个场景。

JSON 文件

  {
    "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 扩展动态制作发布者名称。

【问题讨论】:

    标签: json tfs azure-devops


    【解决方案1】:

    我假设你是通过构建发布扩展,你可以添加 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 我没有从构建中发布任何扩展我发布了我的 VSTS 扩展,我只想通过 xml 文件运行时更改我的发布者名称
    • @NitinParashar 在发布运行时?
    • @strain-MSFT 是的
    • @NitinParasha 不,不支持。 (我更新了我的答案)
    • @NitinParasha 我建议您通过构建/发布发布扩展。 marketplace.visualstudio.com/…
    猜你喜欢
    • 1970-01-01
    • 2012-11-10
    • 2021-01-14
    • 1970-01-01
    • 2019-06-09
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 2012-03-06
    相关资源
    最近更新 更多