Gradle 如何使用groovy编辑vsixmanifest而不丢失内容?

Gradle 如何使用groovy编辑vsixmanifest而不丢失内容?,gradle,groovy,Gradle,Groovy,我的问题可能听起来很愚蠢,但我正在努力实现我的结果。我想在不丢失任何内容的情况下编辑和保存vsixmanifest文件的版本。这几乎解决了我的目的,但它删除了一些标签 <?xml version="1.0" encoding="utf-8"?> <Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.

我的问题可能听起来很愚蠢,但我正在努力实现我的结果。我想在不丢失任何内容的情况下编辑和保存vsixmanifest文件的版本。这几乎解决了我的目的,但它删除了一些标签

<?xml version="1.0" encoding="utf-8"?>
<Vsix xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" Version="1.0.0" xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010">
  <Identifier Id="Visual Test">
    <Name>Visual Gallery Test</Name>
    <Author>Visual Studio Demo</Author>
    <Version>XXXXX</Version>
    <Description xml:space="preserve">Visual Studio Gallery Demo</Description>
    <Locale>1033</Locale>
    <AllUsers>true</AllUsers>
    <InstalledByMsi>false</InstalledByMsi>
    <Icon>Resources/Icon.png</Icon>
    <PreviewImage>Resources/Preview.png</PreviewImage>
    <SupportedProducts>
      <IsolatedShell Version="7.0">Visual Studio</IsolatedShell>
    </SupportedProducts>
    <SupportedFrameworkRuntimeEdition MinVersion="4.6" MaxVersion="4.9" />
  </Identifier>
  <Content>
    <VsPackage>XX.pkgdef</VsPackage>
  </Content>
</Vsix> 
当我执行脚本时,它会删除一些标记定义清单文件,这是执行任务后它的处理方式:

<Vsix xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010" Version="1.0.0">
  <Identifier Id="Visual Test">
    <Name>Visual Gallery Test</Name>
    <Author>Visual Studio Demo</Author>
    <Version>YYYYY</Version>
    <Description xml:space="preserve" xmlns:xml="http://www.w3.org/XML/1998/namespace">Visual Studio Gallery Demo</Description>
    <Locale>1033</Locale>
    <AllUsers>true</AllUsers>
    <InstalledByMsi>false</InstalledByMsi>
    <Icon>Resources/Icon.png</Icon>
    <PreviewImage>Resources/Preview.png</PreviewImage>
    <SupportedProducts>
      <IsolatedShell Version="7.0">Visual Studio</IsolatedShell>
    </SupportedProducts>
    <SupportedFrameworkRuntimeEdition MinVersion="4.6" MaxVersion="4.9"></SupportedFrameworkRuntimeEdition>
  </Identifier>
  <Content>
    <VsPackage>XX.pkgdef</VsPackage>
  </Content>
</Vsix>

视觉画廊测试
VisualStudio演示
YYYY
VisualStudioGallery演示
1033
真的
假的
参考资料/Icon.png
参考资料/Preview.png
Visual Studio
二十、 pkgdef
一些不需要的编辑:

Line1 removed: <?xml version="1.0" encoding="utf-8"?>
Line2 modified to <Vsix xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010" Version="1.0.0">
Tag "Description" got edited too..
Line1已删除:
第2行修改为
标记“Description”也已被编辑。。

我怎样才能避免这种编辑?我只是希望通过我的gradle构建脚本将版本从XXXXX修改为YYYY,而不更改任何其他内容。

这是因为
XmlNodePrinter

如果需要
xml
标记声明,请使用
XmlUtil.serialize()


您可以快速尝试

,但生成的输出非常有效。您在以后使用时是否遇到任何错误?不,我没有遇到任何错误,但无法理解删除/编辑行的原因。
Line1 removed: <?xml version="1.0" encoding="utf-8"?>
Line2 modified to <Vsix xmlns="http://schemas.microsoft.com/developer/vsx-schema/2010" Version="1.0.0">
Tag "Description" got edited too..
def vsixmanifest = new XmlSlurper().parse(vsixmanifestFile)
vsixmanifest.Identifier[0].Version.replaceBody ( "YYYYY" )
println groovy.xml.XmlUtil.serialize(vsixmanifest)