如何使用Powershell更新exe.manifest文件中的版本?

时间:2020-01-24 08:35:59

标签: xml powershell

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
<assemblyIdentity
    version="0.0.0.0"
    processorArchitecture="X86"
    name="ABC"
    type="win32"
/>

我想使用Powershell脚本更新版本。 我尝试编写这段代码

$manifest =[xml]( Get-Content $file.fullname)
$manifest.assemblyIdentity.version = "6.2.0.0" 

它不起作用。

2 个答案:

答案 0 :(得分:1)

[xml]$xml = Get-Content $file.fullname
$xml.assembly.assemblyIdentity.version = "6.2.0.0"
$xml.Save($file.fullname)

答案 1 :(得分:-1)

使用此:

$xmlPath = "FilePath"
$xml = New-Object XML
$xml.Load($xmlPath)
$Namespace = New-Object -TypeName "Xml.XmlNamespaceManager" -ArgumentList $xml.NameTable
$Namespace.AddNamespace("schemas-microsoft-com", $xml.DocumentElement.NamespaceURI)
$nodes =  $xml.SelectNodes("schemas-microsoft-com:assemblyIdentity")
ForEach ($node in $nodes) {
  $node.SetAttribute("version", "6.2.0.0")
}
$xml.Save($xmlPath)