我目前正在开展测试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.
我有一种感觉我走在正确的轨道上,因为它给了我一个与pragma相关的警告,但老实说,我不知道我在这里做什么。这似乎是一个未知领域。
有谁知道我做错了什么,还是指出了我正确的方向?
更新
好像我的项目就是问题所在。我在另一个项目中使用了我的扩展,它就像一个魅力。
对于将来阅读此内容的人,语法为<?pragma prefix.name args?>
,其中参数只是一个字符串。作为旁注,您不要在覆盖方法中关闭XmlWriter
。
答案 0 :(得分:0)
首先,确保您将-ext path\to\YourPragmaExtensionAssembly.dll
传递给candle.exe
。 Candle将加载您的扩展程序,查找指向继承自WixExtension的类的AssemblyDefaultWixExtension
属性,如果您覆盖PreprocessorExtension
属性,则请求您的PreprocessorExtension
类。
可以在WiX工具集的未来版本(如v4.0)中进行简化。但是,在src\ext\PreProcExampleExtension\wixext
的WiX v3.x工具集中有一个示例应该显示出来。