RegisterValue - <> in name - wix

I have this piece of code:
<Component Id="defaultInstallDirRegistry_component" Guid='{XXXXXX}'>
<RegistryValue Root="HKLM" Key="Software\[Manufacturer]\[ProductName]\ExchangeDatabase" Name="<default>" Value="" Type="string" Action="write" KeyPath='yes' />
</Component>
but when I try to compile ti
error CNDL0104 : Not a valid source file; detail: '<', hexadecimal
value 0x3c, is an invalid character.
I know that cause a problem but do not know how to solve it... I tried use CDATA but it does not help...
Any idea? Thanks

Or you can use the standard XML entity encoding for the '<' character since that is the core issue in this situation.
Change: 'Name="<default>" '
To: 'Name="<default>" ' (will work, and is easy for humans to read)
Or to: 'Name="<default>" ' (for more consistent reading)

Ok, so solution to this problem is use notation &#x3c ; (without whitespace) so if you want to write such a character just use notation &#xNNNN where NNNN is hexa code of your char...

Related

WIX How to include the equal signs and ampersand in the string table to avoid LGHT0104 error

I have a launch condition error string in String_en-US.wxl:
<WixLocalization Culture="en-us" Codepage="1252" xmlns="http://schemas.microsoft.com/wix/2006/localization">
<String Id="ERR_REQUIRED_APP_ABSENT">This product requires XXX to be on the system. Please download it from "https://knowledge.xxx.com/knowledge/llisapi.dll?func=ll&objId=59284919&objAction=browse&sort=name&viewType=1", install it and try again.</String>
</WixLocalization>
It seems having the ampersand signs (&) and the equal signs (=) cause the light error:
Strings_en-US.wxl(0,0): error LGHT0104: Not a valid localization file; detail: '=' is an unexpected token. The expected token is ';'. Line 36, position 172.
I even tried to escape them using = which is equivalent to the equal sign but it complaint about the ampersand. "How can I avoid the error?
CDATA: A CDATA section is "...a section of element content that is marked for the parser to interpret as only character data, not markup."
In this case, something like this:
<String Id="TEST1"><![CDATA[https://www.hi.com/one&two&three&v=1]]></String>
XML Escape Characters: XML escape characters are normally used for encoding special characters in XML documents. The escape character for & is & & (more) - CDATA is an alternative approach.
Links:
What characters do I need to escape in XML documents?
https://en.wikipedia.org/wiki/CDATA

Can I do "string contains" in a WiX if statement?

Can I do the following and see if the configuration contains the word "Extra":
<?if $(var.MyProject.Configuration) >< "Extra" ?>
This link suggests I can use >< but it doesn't work for me. It compiles with this error:
error CNDL0162: An illegal number was found in the expression
Short answer: not without writing a preprocessor extension.
The link you provided discusses MSI expressions. The WiX preprocessor is slightly different and doesn't have the substring operators (or bitwise numeric operators for that matter).

XSL node selection by attribute value

I am having some problem with the following xsl command:
<xsl:value-of select="./a/b/c[#code='$codeVal']" />
codeVal is a variable which holds the value of another attribute from some other section of the XML.
The above statement does not work. Debugging shows that $codeVal variable does contain a valid/correct value
However, if I hardcode values then everything just works fine
for example, the following statements work:
<xsl:value-of select="./a/b/c[#code='one']" />
<xsl:value-of select="./a/b/c[#code='two']" />
Can anyone suggest what is wrong with the statement above?
Thank you
Found the issue, I should be referencing variables without quotes.
Instead of $codeVal in single quotes:
xsl:value-of select="./a/b/c[#code='$codeVal']" />
I should have written the statement in the following way:
xsl:value-of select="./a/b/c[#code=$codeVal]" />

msbuild with multiple DefineConstant values, including embedded semicolon

I have an msbuild script which uses the Exec tag to kick off another MSBuild command including a DefineConstants property with multiple values. Since I have multiple values for that property, I'm using the technique described in this question to call MSBuild.exe directly (not use the MSBuild tag) and enclose the values in quotes.
However, I now need to embed a special symbol into one of those values, which I'm attempting to do using the code ¯ (registered trademark ®)
The problem is that the special character code must end in a semicolon, but when I embedded the semicolon, msbuild reads that as a value seperator. I can seem to find a valid way to escape the semicolon and have it still show up in the end parameter value.
My question is this:
How can I embed the special char into my build parameter?
To improve readability, I've moved the value to a variable in my example, but that's not a requirement.
File: TopLevelBuildScript.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Target Name="BuildWithSpecialChar">
<ItemGroup>
<!-- Note: %3B is the escape code for semicolon -->
<MyProductName Include="Trademarked&#174%3B Product" />
<OtherProperty Include="foo" />
</ItemGroup>
<Exec Command="msbuild.exe subBuildScript.proj /p:DefineConstants="MyProductName=#(MyProductName);OtherVar=#(foo);AnotherVar=asdf;" " />
</Target>
</Project>
When executed, the above produces the command line:
msbuild.exe subBuildScript.proj /p:DefineConstants="MyProductName=Trademarked® Product;OtherVar=foo;AnotherVar=asdf;"
Which ends up defining the constants with the product name split at the semicolon:
MyProductName=Trademarked&#174
Product
OtherVar=foo
AnotherVar=asdf
Note: I've also tried using %25 for the percent sign:
<MyProductName Include="Trademarked&#174%253B Product" />
But that gives me:
MyProductName=Trademarked&#174B Product
OtherVar=foo
AnotherVar=asdf
Update
It turns out the issue wasn't with MSBuild, rather with the way WiX parses parameters (my subBuildScript utilizes WiX). I didn't consider that, so didn't mention it in my original posting.
Ultimately, I went with a solution based on this answer to another question:
<PropertyGroup>
<WixValues>
<MyProductName>Trademarked® Product<MyProductName>
<OtherProperty>foo"</OtherProperty>
</WixValues>
</PropertyGroup>
<MSBuild
Projects="subProjectScript.proj"
Properties="Configuration=Release;WixValues=$([MSBuild]::Escape($(WixValues)))"
Targets="Clean;Rebuild"
ContinueOnError="false"
StopOnFirstFailure="true">
</MSBuild>
and unescaping the values in subProjectScript.proj as described in the other answer.
First, MSBuild files are XML, which you can encode as UTF-8, so you should be able to copy/paste the trademark character directly in the MSBuild script, without escaping.
If you can't take that approach, don't escape the ampersand. There are two levels of escaping things in an MSBuild script. The first is XML-encoding, so that XML-sensitive characters (< and &) can be used and you'll still have safe XML. When MSBuild reads in the file, XML-escape sequences get unescaped. After that process, MSBuild then does its own un-escaping (i.e. %3B for semi-colons).
Because you're using & at the beginning of your XMl escape sequence, the XML processor is interpreting that as a literal ampersand, not the special XML ampersand, which denotes an escape sequence. Change your MyProductName item group's value to be:
<MyProductName Include="Trademarked® Product" />
Since MyProductName appears to be a scalar value, and not a list, I would use a property instead:
<PropertyGroup>
<MyProductName>Trademarked® Product</MyProductName>
</PropertyGroup>
In your Exec task you can then use it like this:
<Exec Command="msbuild.exe subBuildScript.proj /p:DefineConstants="MyProductName=$(MyProductName);OtherVar=#(foo);AnotherVar=asdf;" " />

Using "is less than" character (<) in a XML document and parse it

I need to parse a XML document in which there are conditions like the below example:
<element condition="var < 5">element name</element>
The problem is that the parser doesn't allow this 'is less than' (<) character.
I tried GDataXML -> it gives me an error saying there is an illegal character.
I also tried TBXML -> it doesn't take into account the attributes where there is this character.
I guess it's the same for other parsers.
How can I fix this?
You should replace < with <