Someone asked recently how to use an ampersand (&) in the Product Name for their .wxs file. Probably something like:
<Product Name="Stuff & Stuff Demo" ...
The error message itself is pretty brutal but does pinpoint (to the exact character) the problem:
stuff.wxs(3) : error CNDL0104 : Not a valid source file; detail: An error
occurred while parsing EntityName. Line 3, position 27.
The error message is coming from the XML parser (we currently don't try to trap those and print out friendlier error messages, not sure that is even possible) telling you that the the "entity" (things that start with an ampersand) name is invalid. The trick is to realize that ampersands are special characters in XML. Fortunately, this fact is pretty well documented all over the Internet. So the fix is easy:
<Product Name="Stuff & Stuff Demo" ...
The follow up question was how to get an ampersand to show up in the UI. The issue is that if you have something like:
<Control Text="&Print" ...
The control's text is going to look like "Print". For as long as I can remember, Windows dialogs have used used an ampersand to mark the accelerator key (or is it accessibility key?) . So hopefully it is no surprise that the Windows Installer chose to follow the same convention for their dialogs. Anyway, if you really wanted "&Print" to be the text of the control then you'd need to escape the ampersand like:
<Control Text="&&Print" ...
This is one of those cases where the special characters in one language (XML) also used represent special characters another language (MSI UI) end up complicating the escaping across the board. Fortunately, this doesn't happen too often (and isn't nearly as ugly as the escaping of XSL in Formatted text fields).
RobMensching.com LLC
8 Comments
Comment by Roger on Monday, April 21, 2008 10:17 AM
I see that you can show the ampersand in the product name by using one &, but in the CancelDlg it would show an underscored space since the ampersand in ProductName was marked it as the accelerator key.
Now, you "could" put two & to correctly show the ampersand in dialog controls, but then ProductName in the title bar would show 2 ampersands.
I'm not sure how I can get around it...
Comment by Anonymous on Monday, April 21, 2008 11:12 AM
Comment by Rob Mensching on Monday, April 21, 2008 3:38 PM
Anyway, one way to work around this is to brute force replace the ProductName property anywhere it shows up in a control's text. Or, I suppose you could just create a ProductNameSafeForUI property (or some such) and double encode the name there. Or you could change the product's name to not contain an ampersand (but that might be harder than the rest <smile/>).
Comment by Rob Mensching on Monday, April 21, 2008 3:40 PM
Comment by Mike Dimmick on Tuesday, April 22, 2008 2:11 AM
It's a source of continual frustration that the Windows default is to enable this feature when it's so rarely needed. The .NET Compact Framework team were idiotic enough to leave out Label.UseMnemonic which means you can't turn it off on that platform. Not helpful when you want to databind a Label control. I reported it as a bug and it got closed as 'By Design'.
Comment by Roger Lipscombe on Tuesday, April 22, 2008 2:53 AM
Comment by Roger on Tuesday, April 22, 2008 8:27 AM
Another interesting thing that I saw, the references to [ProductName] in some of the "bigger" dialogs such as WelcomeDlg and ExitDlg are shown correctly, so I guess NoPrefix is set in those text controls. But not in CancelDlg. Would this be a bug, in WiX or the Windows Installer itself?
Comment by Rob Mensching on Tuesday, April 22, 2008 10:05 AM
Roger, let's first assume the bug is in the standard WiX UI. More likely than not we just missed a few controls with that attribute.