简体   繁体   中英

Require xml namespace prefix on attribute in child node

I am attempting to make modifications to a ClickOnce deployment manifest. One thing I need to do is setup the manifest to deploy an icon to the desktop. To do this you need to add the createDesktopShortcut attribute with a true value to the Deployment node.

For Example, this is a snippet of a working deployment file (there are some minor modifications).

<?xml version="1.0" encoding="utf-8"?>
<asmv1:assembly xsi:schemaLocation="urn:schemas-microsoft-com:asm.v1 assembly.adaptive.xsd"
                manifestVersion="1.0" 
                xmlns:asmv1="urn:schemas-microsoft-com:asm.v1" 
                xmlns="urn:schemas-microsoft-com:asm.v2" 
                xmlns:asmv2="urn:schemas-microsoft-com:asm.v2"
                xmlns:xrml="urn:mpeg:mpeg21:2003:01-REL-R-NS" 
                xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
                xmlns:asmv3="urn:schemas-microsoft-com:asm.v3"
                xmlns:dsig="http://www.w3.org/2000/09/xmldsig#" 
                xmlns:co.v1="urn:schemas-microsoft-com:clickonce.v1" 
                xmlns:co.v2="urn:schemas-microsoft-com:clickonce.v2">
  <assemblyIdentity name="My.app" version="1.2.3.4" publicKeyToken="redacted" language="neutral" processorArchitecture="x86" xmlns="urn:schemas-microsoft-com:asm.v1" />
  <deployment trustURLParameters="true" install="true" 
              minimumRequiredVersion="1.2.3.4"
              co.v1:createDesktopShortcut="true">
    <subscription>
      <update>
        <beforeApplicationStartup />
      </update>
    </subscription>
    <deploymentProvider codebase="redacted" />
  </deployment>
</asmv1:assembly>

Note that the attribute "createDesktopShortcut" is prefixed with the namespace co.v1 This prefix appears to be required, however if you attempt to use Power Shell to create this element it will add it without the prefix, making the xml invalid.

[xml]$DeploymentManifest = Get-Content -Path $DeploymentPath 
$DeploymentManifest.assembly.SetAttribute("xmlns:co.v1", "urn:schemas-microsoft-com:clickonce.v1")
$DeploymentManifest.assembly.deployment.SetAttribute('co.v1:createDesktopShortcut',
                                                         'true')

This results in the following Deployment tag:

    <deployment trustURLParameters="true" install="true" 
            minimumRequiredVersion="1.2.3.4" 
            createDesktopShortcut="true" >

This would be fine, however ClickOnce can't seem to process that attribute without the prefix. Any guidance in any direction as to why this happens or how I can cleanly work around it is appreciated.

I'm not quite sure why that doesn't work. It seems to contradict the documentation for the SetAttribute method. However using the other overload of SetAttribute or SetAttributeNode did work for me.

via SetAttribute:

$DeploymentManifest.assembly.deployment.SetAttribute('createDesktopShortcut', 'urn:schemas-microsoft-com:clickonce.v1', 'true')

or via SetAttributeNode:

$att = $DeploymentManifest.assembly.deployment.SetAttributeNode('createDesktopShortcut', 'urn:schemas-microsoft-com:clickonce.v1')
$att.Value = 'true'

and the output:

<deployment trustURLParameters="true" 
    install="true" 
    minimumRequiredVersion="1.2.3.4" 
    co.v1:createDesktopShortcut="true">

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM