题
我想在Wix wxs文件中添加一个不相关的属性,并希望Wix忽略它。
当它寻找扩展时,它当前会抛出以下错误。
Component元素包含未处理的扩展属性'myns:myattr'。请确保“ http://tempuri.org/myschema.xsd ”中的属性扩展名已提供名称空间。
Rob,Bob或wix团队的任何人都在听!!:)
解决方案
编写一个wix扩展名,用于处理该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
如果您现在使用-ext mywixext.dll
选项编译wix源(或者在votive中执行等效操作),那么WIX
命名空间中的所有元素都将被忽略。
编辑:当我说任何元素都会被忽略时,我感到不精确。 WIX XML模式不允许您直接在<xs:any namespace="##other" processContents="lax">
元素下添加自己的子元素。大多数其他元素允许它。在c:\program files\windows installer xml v3\doc\wix.xsd
中查找文本<=>以查找可扩展性点。
不隶属于 StackOverflow