我目前正在进行一个测试WiX项目,看看我能用它做什么。
最近,我偶然发现,我可以在我的预处理器扩展中重写ProcessPragma方法,以便在编译时编写WiX源代码。拥有一个预处理器函数来返回xml字符串,而不需要编译器疯狂,听起来很不错。因此,我研究了它,但在这个wix用户线程中的反应是相当简短的,并没有解释太多。除此之外,谷歌不会返回任何有趣的东西。因此,我深入研究了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 prefix.name args?>,其中的参数只是一个字符串。另外,在您的重写方法中,您不关闭XmlWriter。
发布于 2013-02-27 14:55:03
首先,确保将-ext path\to\YourPragmaExtensionAssembly.dll传递给candle.exe。蜡烛将加载您的扩展,查找指向从AssemblyDefaultWixExtension继承的类的WixExtension属性,如果覆盖PreprocessorExtension属性,则请求您的PreprocessorExtension类。
在WiX工具集的未来版本(如v4.0)中,可以简化一些连接。但是,在WiX v3.x工具集at:src\ext\PreProcExampleExtension\wixext中有一个示例应该说明方法。
https://stackoverflow.com/questions/15080337
复制相似问题