我在读一本json文件。更新几个值并将其写回原样。有些元素最终会失去秩序。
$manifest = (gc $manifestPath -raw) | ConvertFrom-Json -AsHashtable
$manifest.name = "$($manifest.name)-sxs"
$manifest | ConvertTo-Json -depth 100 | Out-File $manifestPath -Encoding utf8NoBOM原始档案有:
{
"name": "vsVersion",
"type": "pickList",
"label": "Visual Studio Version",
"required": false,
"helpMarkDown": "If the preferred version cannot be found, the latest version found will be used instead.",
"defaultValue": "latest",
"options": {
"latest": "Latest",
"17.0": "Visual Studio 2022",
"16.0": "Visual Studio 2019",
"15.0": "Visual Studio 2017",
"14.0": "Visual Studio 2015",
"12.0": "Visual Studio 2013",
"11.0": "Visual Studio 2012"
}
},已写入的文件有:
{
"required": false,
"type": "pickList",
"name": "vsVersion",
"options": {
"11.0": "Visual Studio 2012",
"12.0": "Visual Studio 2013",
"14.0": "Visual Studio 2015",
"17.0": "Visual Studio 2022",
"15.0": "Visual Studio 2017",
"16.0": "Visual Studio 2019",
"latest": "Latest"
},
"helpMarkDown": "If the preferred version cannot be found, the latest version found will be used instead.",
"label": "Visual Studio Version",
"defaultValue": "latest"
},是否有办法保留元素的原始顺序?
发布于 2022-08-17 15:43:21
好的,这是REALLY recently fixed in v7.3.0-preview.6。
最后,我将它添加到我的GitHub操作工作流中,以使用预览版本而不是主版本:
- run: |
Invoke-Expression "& { $(irm https://aka.ms/install-powershell.ps1) } -UseMSI -preview -quiet"
"C:\Program Files\PowerShell\7-preview" >> $env:GITHUB_PATH
name: Upgrade to latest preview of powershell
# https://github.com/PowerShell/PowerShell/issues/17404#issuecomment-1188348379这神奇地解决了我的问题。
https://stackoverflow.com/questions/73389697
复制相似问题