How can I add attributes and elements from a new namepace in Wix and ignored by Wix?

StackOverflow https://stackoverflow.com/questions/1803593

  •  05-07-2019
  •  | 
  •  

Question

I want to add a unrelated attribute in the Wix wxs file and want Wix to ignore it.

It currently throws up following error as it goes looking for the extension.

The Component element contains an unhandled extension attribute 'myns:myattr'. Please ensure that the extension for attributes in the 'http://tempuri.org/myschema.xsd' namespace has been provided.

Rob, Bob or anybody on wix team listening!!:)

Was it helpful?

Solution

Write a wix extension which handles elements in that XML namespace. The following example extension will cause any elements in the namespace http://www.example.com to be ignored:

Save the following code in 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
      }

   }
}

Now compile it into mywixext.dll like this:

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

If you now compile your wix sources with the option -ext mywixext.dll (or do the equivalent in votive) then all elements in the http://www.example.com namespace will be ignored.

edit: I was imprecise when I said that any element would be ignored. The WIX XML schema does not allow you to add your own child elements directly under the WIX element. Most other elements allow it. Look for the text <xs:any namespace="##other" processContents="lax"> in c:\program files\windows installer xml v3\doc\wix.xsd to find the extensibility points.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top