代码之家  ›  专栏  ›  技术社区  ›  Rohit

如何从WIX中的新名称空间添加属性和元素并被WIX忽略?

  •  2
  • Rohit  · 技术社区  · 16 年前

    我想在wix wxs文件中添加一个不相关的属性,并希望wix忽略它。

    在查找扩展名时,它当前引发以下错误。

    组件元素包含未处理的扩展属性“myns:myattr”。请确保“”中属性的扩展名 http://tempuri.org/myschema.xsd '已提供命名空间。

    Rob,Bob或Wix团队的任何人在听!!)

    1 回复  |  直到 16 年前
        1
  •  1
  •   Wim Coenen    16 年前

    Write a wix extension 它处理该XML命名空间中的元素。下面的示例扩展将导致命名空间中的任何元素 http://www.example.com 被忽视:

    将以下代码保存在 mywixext.cs :

    using System.Xml.Schema;
    using Microsoft.Tools.WindowsInstallerXml;
    using System.Xml;
    
    [assembly: AssemblyDefaultWixExtension(
       typeof(mywixext.IgnoreNamespaceWixExtension))]
    
    namespace mywixext
    {
    
       public class IgnoreNamespaceWixExtension : WixExtension
       {
          public override CompilerExtension CompilerExtension
          {
             get
             {
                return new IgnoreNamespaceCompilerExtension();
             }
          }
       }
    
       public class IgnoreNamespaceCompilerExtension : CompilerExtension
       {
          public override XmlSchema Schema
          {
             get
             {
                return new XmlSchema() 
                {
                   TargetNamespace = "http://www.example.com" 
                };
             }
          }
    
          public override void ParseElement(
             SourceLineNumberCollection sourceLineNumbers,
             XmlElement parentElement, XmlElement element,
             params string[] contextValues)
          {
             // do nothing
          }
    
       }
    }
    

    现在编译成 mywixext.dll 这样地:

    "c:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe" /t:library ^
    /r:"c:\program files\windows installer xml v3\bin\wix.dll" ^
    mywixext.cs
    

    如果现在使用选项编译wix源 -ext mywixext.dll (或在votive中执行等效操作)然后 网址:http://www.example.com 将忽略命名空间。

    编辑 :当我说任何元素都将被忽略时,我是不精确的。WIX XML架构不允许您直接将自己的子元素添加到 WIX 元素。大多数其他元素都允许这样做。查找文本 <xs:any namespace="##other" processContents="lax"> 在里面 c:\program files\windows installer xml v3\doc\wix.xsd 找到可扩展性点。

    推荐文章