tags:

views:

185

answers:

1

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!!:)

+1  A: 

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.

Wim Coenen
It now gives error that unexpected attribute.
Rohit
I had tested with my own child element under `<Package>`. You are probably attempting to add stuff directly under `<Wix>`. I have edited my answer to clarify why this is not allowed.
Wim Coenen
Because we cannot add attributes to Wix elements but can add new elements to Wix elements.
Rohit