The preprocessor, while not a macro preprocessor (like what the C/C++ compiler has), does have a number of "macro-preprocessor-like" features. One of the "holes" in that is the case you see.
The source files are parsed using an XML stream parser. Text fields (such as attribute values and element text values) are passed to the preprocessor for evaluation, as are all processing instructions, in the order they are parsed by the parser. Once the preprocessor finishes, a DOM has resulted, which is then parsed by the compiler. The only current way to do what you want would be to use an external preprocessor (would likely be non-XML) of your own choosing and pass the preprocessed result to candle.exe. However, I have wanted to do authoring in a similar way many times, especially when building wixlibs to be incorporated in WiX extensions. Seems like a valid feature request. Please feel free to file one. -----Original Message----- From: Bryan Reich [mailto:bryan.re...@microsoft.com] Sent: Friday, February 12, 2010 9:29 PM To: 'General discussion for Windows Installer XML toolset.' Subject: [WiX-users] Using variables to define attributes (not attribute values) I was under the impression that the expression $(var.MyVar) a preprocessor evaluation, evaluated at a similar time to <?if ?>. However, some wix that I am compiling suggests this isn't the case. I'm trying to define a variable as follows: <?if someCondition ?> <?define MyVariable="Server="MyServer.exe""?> <?else ?> <?define MyVariable=""?> <?endif ?> And then my wix example as: <Class Id="<GUID>" ... $(var.MyVariable) > ... </Class> So in other words, in case one preprocessor condition is set, I want the attribute text specified in MyVariable to show up in the Class element definition, and otherwise I don't. Note that specifying the value of the attribute as empty I don't think is acceptable because in the case where I have the attribute non-existant, it would be an error to have the attribute defined at all, even as empty (someone can correct me if these are in fact equivalent to the compiler). However, when trying to compile this I get the error: error CNDL0104 : Not a valid source file; detail: Name cannot begin with the '$' character, hexadecimal value 0x24. Line 33, position 163. So instead of taking the varaible contents and replacing them and then parsing the XML, it appears to be trying to parse the XML first, and then replacing the variables, which leads to only being able to use them in attribute values but not in the XML itself. Is there a way to do what I am after without resorting to duplicating a bunch of wix XML within <?if ?><?else ?> blocks to conditionally include or exclude the attribute at compile time? -- Bryan ---------------------------------------------------------------------------- -- SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ WiX-users mailing list WiX-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wix-users ------------------------------------------------------------------------------ SOLARIS 10 is the OS for Data Centers - provides features such as DTrace, Predictive Self Healing and Award Winning ZFS. Get Solaris 10 NOW http://p.sf.net/sfu/solaris-dev2dev _______________________________________________ WiX-users mailing list WiX-users@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/wix-users