Update Xml File (vsixmanifest)

我是研究僧i 提交于 2019-12-02 13:23:07

问题


I'm creating a Visual Studio 2013 Package (vsix) (shameless plug: pMixins ). As part of my quest to use TeamCity as a continuous integration server, I have configured Team City to build the .vsix Package (Visual Studio Package (vsix) - Team City without Visual Studio installed).

Now I want to configure Team City to set the Version in the VSIX Schema:

<?xml version="1.0" encoding="utf-8"?>
<PackageManifest 
    Version="2.0.0" 
    xmlns="http://schemas.microsoft.com/developer/vsx-schema/2011" 
    xmlns:d="http://schemas.microsoft.com/developer/vsx-schema-design/2011">
    <Metadata>
        <Identity  Version="1.0" Language="en-US" Publisher="Company" />

Following the advice in Using msbuild I want to update a config file with values from teamcity and How do I update an XML attribute from an MSBuild script? I have updated Microsoft.VsSDK.targets to use XmlPoke with the following Target:

<Target 
     Name="UpdateVSIXVersion" 
     BeforeTargets="PrepareForBuild" 
     Condition="$(VSIXVersion) != '' And $(VSIXVersion) != '*Undefined*'">

    <Message Text= "Updating VSIX Version" />

    <XmlPoke 
        XmlInputPath="source.extension.vsixmanifest"
        Query="/PackageManifest/Metadata/Identity/@Version"
        Value="$(VSIXVersion)">         
    </XmlPoke>      
 </Target>

I updated Team City with a system Parameter to set VSIXVersion:

But, when I check TeamCity, it made 0 replacements:

How do I get Team City to correctly update the .vsixmanifest xml?


回答1:


After much searching I finally found the XmlPoke expects a namespace when the Xml file contains a namespace, even for the default namespace (Modifying .config File in an MSBuild Project).

However, I couldn't find any documentation for the XmlPoke.Namespaces parameter and the above referenced code didn't work. After much trial an error, I finally got it to work with this:

<Target 
    Name="UpdateVSIXVersion" 
    BeforeTargets="PrepareForBuild" 
    Condition="$(VSIXVersion) != '' And $(VSIXVersion) != '*Undefined*'">

    <Message Text= "Updating VSIX Version" />

    <XmlPoke 
        XmlInputPath="source.extension.vsixmanifest"
        Query="/n:PackageManifest/n:Metadata/n:Identity/@Version"
        Value="$(VSIXVersion)"
        Namespaces="&lt;Namespace Prefix='n' Uri='http://schemas.microsoft.com/developer/vsx-schema/2011' Name='DoNotKnowWhatThisIsFor-ButItIsRequired' /&gt;">
    </XmlPoke>      

Notes:

  • This requires MSBuild 12 to be configured on Team City
  • The Namespaces needs to be escaped.
  • The Name parameter is required, otherwise MSBuild will error out
  • The original XPath query had to be updated with the artificial namespace prefix.

MSBuild file is on Github if anyone needs it: https://github.com/ppittle/pMixins/blob/master/tools/vssdk_tools/v12.0/VSSDK/Microsoft.VsSDK.targets



来源:https://stackoverflow.com/questions/24328738/update-xml-file-vsixmanifest

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!