Wix脚本中的转义括号
我有一个名为Wix脚本中的转义括号,wix,Wix,我有一个名为MyProject(P2P)的VisualStudio项目,它一直运行良好 现在我使用Wix 3将此项目打包到MSI中,其中一个步骤是编写组件节点: 现在我得到了Wix项目的构建错误: wxs(807,0):错误CNDL0234:格式错误的预处理器函数“$var.MyProject(P2P).TargetPath”。函数必须有前缀(如“fun”)、至少1个字符长的名称以及匹配的左括号和右括号 看起来需要退出(和)?怎么做呢?从WIX 3.11开始,变量名中没有转义括号的机制。WI
MyProject(P2P)
的VisualStudio项目,它一直运行良好
现在我使用Wix 3将此项目打包到MSI中,其中一个步骤是编写组件节点:
现在我得到了Wix项目的构建错误:
wxs(807,0):错误CNDL0234:格式错误的预处理器函数“$var.MyProject(P2P).TargetPath”。函数必须有前缀(如“fun”)、至少1个字符长的名称以及匹配的左括号和右括号
看起来需要退出
(
和)
?怎么做呢?从WIX 3.11开始,变量名中没有转义括号的机制。WIX预处理器应该在不需要转义括号的情况下处理此问题,但在您的情况下,由于预处理器中的错误和/或限制,不需要转义括号
要了解发生了什么,我们需要查看相关的WIX源文件src\tools\WIX\PreProcessor.cs
,该文件可从下载。在这个文件中,函数PreprocessString()
获取一个字符串,并尝试用相应的定义替换$(…)
形式的预处理器变量(我没有包括这个函数的源代码,因为它很长)
由于变量包含一个开括号字符,PreprocessString()
函数调用EvaluateFunction()
:
<Component Id="MyProject(P2P).exe" Guid="34565d5d-07d6-495d-a184-bb3bdebe1fb8">
<File Source="$(var.MyProject(P2P).TargetPath)" KeyPath="yes" />
</Component>
/// <summary>
/// Evaluate a function.
/// </summary>
/// <param name="sourceLineNumbers">The source line information for the function.</param>
/// <param name="function">The function expression including the prefix and name.</param>
/// <returns>The function value.</returns>
public string EvaluateFunction(SourceLineNumberCollection sourceLineNumbers, string function)
{
string[] prefixParts = function.Split(variableSplitter, 2);
// Check to make sure there are 2 parts and neither is an empty string.
if (2 != prefixParts.Length || 0 >= prefixParts[0].Length || 0 >= prefixParts[1].Length)
{
throw new WixException(WixErrors.InvalidPreprocessorFunction(sourceLineNumbers, function));
}
string prefix = prefixParts[0];
string[] functionParts = prefixParts[1].Split(new char[] { '(' }, 2);
// Check to make sure there are 2 parts, neither is an empty string, and the second part ends with a closing paren.
if (2 != functionParts.Length || 0 >= functionParts[0].Length || 0 >= functionParts[1].Length || !functionParts[1].EndsWith(")", StringComparison.Ordinal))
{
throw new WixException(WixErrors.InvalidPreprocessorFunction(sourceLineNumbers, function));
}
string functionName = functionParts[0];
// Remove the trailing closing paren.
string allArgs = functionParts[1].Substring(0, functionParts[1].Length - 1);
// Parse the arguments and preprocess them.
string[] args = allArgs.Split(argumentSplitter);
for (int i = 0; i < args.Length; i++)
{
args[i] = this.PreprocessString(sourceLineNumbers, args[i].Trim());
}
string result = this.EvaluateFunction(sourceLineNumbers, prefix, functionName, args);
// If the function didn't evaluate, try to evaluate the original value as a variable to support
// the use of open and closed parens inside variable names. Example: $(env.ProgramFiles(x86)) should resolve.
if (null == result)
{
result = this.GetVariableValue(sourceLineNumbers, function, false);
}
return result;
<Component Id="MyProject(P2P).exe" Guid="34565d5d-07d6-495d-a184-bb3bdebe1fb8">
<File Source="..\Release\MyProject(P2P).exe" KeyPath="yes" />
</Component