Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/wix/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
WIX自定义操作参数中的连接字符串_Wix_Custom Action_Wix3.7 - Fatal编程技术网

WIX自定义操作参数中的连接字符串

WIX自定义操作参数中的连接字符串,wix,custom-action,wix3.7,Wix,Custom Action,Wix3.7,使用WIX3.7,我想将连接字符串传递到自定义操作中。但是,由于连接字符串包含“;”未正确分析自定义操作数据 <CustomAction Id="PopulateActionPrep" Property="PopulateAction" Execute="immediate" Value="CONNECTIONSTRING=&quot;[CONNECTIONSTRING]&quot;;PRODUCTVERSION=[ProductVersion]" /> 我尝

使用WIX3.7,我想将连接字符串传递到自定义操作中。但是,由于连接字符串包含“;”未正确分析自定义操作数据

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

我尝试使用引号来转义连接字符串,但没有成功。当我从CustomActionData读取CONNECTIONSTRING属性时,它返回“Data Source=SqlServerName”


有没有一种方法可以在WIX中转义相等的分号?

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

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

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


您没有说明延迟的自定义操作是用什么语言编写的。使用set属性自定义操作仅在有限的情况下有用。您通常会对立即操作使用代码自定义操作。例如,如果我使用C#DTF自定义操作,我会编写一个自定义操作来创建CustomActionData clas然后我将它序列化为传递到延迟自定义操作的属性

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

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


答案是,您可以使用
来转义

/// <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;
}
这就是
会话的全部内容。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;
    }
}
//
///获取调用方提供的会话的自定义操作数据。
/// 
/// 
公共CustomActionData CustomActionData
{
得到
{
if(this.customActionData==null)
{
this.customActionData=新的customActionData(this[customActionData.PropertyName]);
}
返回此.customActionData;
}
}

答案是,您可以使用
来转义

/// <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;
}
这就是
会话的全部内容。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;
    }
}
//
///获取调用方提供的会话的自定义操作数据。
/// 
/// 
公共CustomActionData CustomActionData
{
得到
{
if(this.customActionData==null)
{
this.customActionData=新的customActionData(this[customActionData.PropertyName]);
}
返回此.customActionData;
}
}

我将连接字符串拆分为多个部分,将这些单独的部分传递给
CustomActionData
,并让自定义操作“构建”此部分的连接字符串。这是一种解决方法。我将连接字符串拆分为多个部分,将这些单独的部分传递给
CustomActionData
,并让自定义操作“构建”“将连接字符串从该部件中删除。一种变通方法。