2

使用 WIX 3.7,我想将连接字符串传递给自定义操作。但是,由于连接字符串包含 ';' 未正确解析自定义操作数据。

<CustomAction Id="PopulateActionPrep" Property="PopulateAction" Execute="immediate" Value="CONNECTIONSTRING=&quot;[CONNECTIONSTRING]&quot;;PRODUCTVERSION=[ProductVersion]" /> 

我尝试使用引号来转义连接字符串,但这不起作用。当我从 CustomActionData 读取CONNECTIONSTRING属性时,它会返回"Data Source=SqlServerName

有没有办法在 WIX 中转义相等的分号?

4

2 回答 2

3

答案是肯定;的,您可以使用以下方法逃脱;;

/// <summary>
/// Escapes a value string by doubling any data-separator (semicolon) characters.
/// </summary>
/// <param name="value"></param>
/// <returns>Escaped value string</returns>
private static string Escape(string value)
{
    value = value.Replace(String.Empty + CustomActionData.DataSeparator, String.Empty + CustomActionData.DataSeparator + CustomActionData.DataSeparator);
    return value;
}

https://github.com/wixtoolset/wix3/blob/wix311rtm/src/DTF/Libraries/WindowsInstaller/customactiondata.cs#L391-L400Unescape ;另见Parse下文。)

可能更好的消息,您可以将数据作为原始字符串访问,并完全控制它的反序列化方式:

var rawString = session["CustomActionData"];

这就是所有Session.CustomActionData正在做的事情:

/// <summary>
/// Gets custom action data for the session that was supplied by the caller.
/// </summary>
/// <seealso cref="DoAction(string,CustomActionData)"/>
public CustomActionData CustomActionData
{
    get
    {
        if (this.customActionData == null)
        {
            this.customActionData = new CustomActionData(this[CustomActionData.PropertyName]);
        }


        return this.customActionData;
    }
}

https://github.com/wixtoolset/wix3/blob/wix311rtm/src/DTF/Libraries/WindowsInstaller/Session.cs#L859-L874

于 2017-10-26T23:50:49.220 回答
1

您没有说延迟自定义操作是用什么语言编写的。使用设置属性自定义操作仅在有限的情况下有用。您通常所做的也是立即使用代码自定义操作。例如,如果我正在使用 C# DTF 自定义操作,我会编写一个自定义操作来创建一个 CustomActionData 类并用我的字典填充它。然后我会将它序列化为传递给延迟自定义操作的属性。

一旦进入延迟的自定义操作,我通过反序列化 CustomActionData 属性创建一个新的 CustomActionData 类,然后访问我的数据字典。

通过利用 CustomActionData 类,您不必发明自己的结构化和转义数据的方式。有关更核心的示例,请参阅我使用 JSON 的博客。

Beam Me Up:使用 JSON 序列化 CustomActionData

于 2013-10-04T18:39:40.550 回答