[wix-users] Extensibility

Szentpáli, János szentpalijanos at gmail.com
Thu Nov 5 16:54:09 PST 2015


OK, I think I did it.
Here's if anyone is interested (of course any
comments/suggestions/corrections are still welcomed):

C# library:
-----------

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Tools.WindowsInstallerXml;

namespace Tag
{
    public class Tag : WixExtension
    {
        private CompilerExtension compiler_extension;

        public override CompilerExtension CompilerExtension
        {
            get
            {
                if (compiler_extension == null) {
                    compiler_extension = new TagCompiler ();
                }

                return compiler_extension;
            }
        }
    }

    public class TagCompiler : CompilerExtension
    {
        private System.Xml.Schema.XmlSchema schema;

        public TagCompiler ()
        {
            schema = System.Xml.Schema.XmlSchema.Read
(System.Reflection.Assembly.GetExecutingAssembly
().GetManifestResourceStream ("Tag.Tag.xsd"), null);
        }

        public override System.Xml.Schema.XmlSchema Schema
        {
            get
            {
                return schema;
            }
        }

        public override void ParseAttribute (SourceLineNumberCollection
sourceLineNumbers, System.Xml.XmlElement parentElement,
System.Xml.XmlAttribute attribute)
        {
            Console.WriteLine ("ParseAttribute (1): " + "\t" +
parentElement.Name + "\t" + attribute.Name);
        }

        public override void ParseAttribute (SourceLineNumberCollection
sourceLineNumbers, System.Xml.XmlElement parentElement,
System.Xml.XmlAttribute attribute, Dictionary<string, string> contextValues)
        {
            Console.WriteLine ("ParseAttribute (2): " + "\t" +
parentElement.Name + "\t" + attribute.Name);
        }
    }
}

Schema file (Tag.Tag.xsd resource):
-----------------------------------

<?xml version="1.0" encoding="utf-8"?>
<xs:schema
    xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns:wix="http://schemas.microsoft.com/wix/2006/wi"
    xmlns:xs="http://www.w3.org/2001/XMLSchema"
    xmlns:xse="http://schemas.microsoft.com/wix/2005/XmlSchemaExtension"
    targetNamespace="http://schemas.entity.root/wix/2015/tag"
    xmlns="http://schemas.entity.root/wix/2015/tag"
>
    <xs:attribute name="Tag" type="xs:string" >
        <xs:annotation>
            <xs:documentation>
                Some text...
            </xs:documentation>
            <xs:appinfo>
                <xse:parent
namespace="http://schemas.microsoft.com/wix/2006/wi" ref="Feature" />
            </xs:appinfo>
        </xs:annotation>
    </xs:attribute>
</xs:schema>

WIX Feature:
------------

<?xml version="1.0" encoding="windows-1252"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"
xmlns:tag="http://schemas.entity.root/wix/2015/tag">
    <Fragment>
        <Feature
            ...
            tag:Tag="<whatever information>"
            ...
        >
        </Feature>
    </Fragment>
</Wix>

Regards,
János


More information about the wix-users mailing list