我目前正在测试WiX项目,看看我能用它做什么。如何使用WiX预处理器编译指示?
最近,我偶然发现我可以覆盖预处理器扩展中的ProcessPragma
方法来在编译时编写WiX源代码。有一个预处理函数返回一个xml字符串,而编译器不会听起来很干净。所以我研究了它,但this wix-users thread中的回答非常简短,并没有太多解释。除此之外,Google不会返回任何有趣的内容。所以我通过WiX源代码挖掘了解更多信息。
该方法的XML文档如下:
/// <summary>
/// Processes a pragma defined in the extension.
/// </summary>
/// <param name="sourceLineNumbers">The location of this pragma's PI.</param>
/// <param name="prefix">The prefix of the pragma to be processed by the extension.</param>
/// <param name="pragma">The name of the pragma.</param>
/// <param name="args">The pragma's arguments.</param>
/// <param name="writer">The xml writer.</param>
/// <returns>false if the pragma is not defined.</returns>
/// <comments>Don't return false for any condition except for unrecognized pragmas.
Throw errors that are fatal to the compile. use core.OnMessage for warnings and messages.</comments>
那么作为一个测试,我有XmlWriter
产生一个虚拟的属性,然后返回true。
现在,在我的WiX项目中实际调用它。在Preprocessor.cs
,我发现:
switch (reader.NodeType)
{
case XmlNodeType.ProcessingInstruction:
switch (reader.LocalName)
{
// other cases such as define, include, foreach,
// and other preprocessor directives
case "pragma":
this.PreprocessPragma(reader.Value, writer);
break;
}
break;
这暗示了使用编译的语法是:<?pragma prefix.name?>
但是这给了我以下警告:The pragma 'prefix.name' is unknown. Please ensure you have referenced the extension that defines this pragma.
我有一种感觉,我在正确的轨道上,因为它给了我一个关于编译指示的警告,但我真的不知道我在这里做什么。这似乎是未知的领域。
有谁知道我做错了什么,或者指出我在正确的方向吗?
UPDATE
好像我的项目是问题。我在另一个项目中使用了我的扩展,它的功能就像一个魅力。
对于任何人在将来阅读此文,语法是<?pragma prefix.name args?>
其中参数只是一个字符串。作为一个方面说明,您不要在覆盖方法中关闭XmlWriter
。
看来问题出在我的项目中,而不是扩展本身。我试图在另一个项目中使用它,它工作正常。 – Netfangled 2013-03-01 00:31:40