简体   繁体   English

在子节点的属性上需要xml名称空间前缀

[英]Require xml namespace prefix on attribute in child node

I am attempting to make modifications to a ClickOnce deployment manifest. 我正在尝试对ClickOnce部署清单进行修改。 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. 为此,您需要将具有真实值的createDesktopShortcut属性添加到Deployment节点。

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. 请注意,属性“ createDesktopShortcut”以名称空间co.v1为前缀。此前缀似乎是必需的,但是,如果您尝试使用Power Shell创建此元素,它将添加没有前缀的元素,从而使xml无效。

[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标签:

    <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. 很好,但是没有前缀,ClickOnce似乎无法处理该属性。 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. 似乎与SetAttribute方法的文档相矛盾。 However using the other overload of SetAttribute or SetAttributeNode did work for me. 但是,使用SetAttributeSetAttributeNode的其他重载确实对我SetAttributeNode

via SetAttribute: 通过SetAttribute:

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

or via SetAttributeNode: 或通过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">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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