WIX自定义操作参数中的连接字符串 [英] Connection String in a WIX Custom Action Parameter
问题描述
使用WIX 3.7,我想将连接字符串传递到自定义操作中。但是,由于连接字符串包含;,因此自定义操作数据无法正确解析。
Using WIX 3.7, I want to pass a connection string into a custom action. However, since the connection string contains ';' the custom action data is not being parsed correctly.
<CustomAction Id="PopulateActionPrep" Property="PopulateAction" Execute="immediate" Value="CONNECTIONSTRING="[CONNECTIONSTRING]";PRODUCTVERSION=[ProductVersion]" />
我尝试使用引号对连接字符串进行转义,但这没有用。当我从CustomActionData中读取 CONNECTIONSTRING 属性时,它会返回 Data Source = SqlServerName 。
I tried using quotes to escape the connection string but that did not work. When I read the CONNECTIONSTRING property from CustomActionData it comes back with "Data Source=SqlServerName.
如何在WIX中转义等分号?
Is there a way to escape equal semicolons in WIX?
推荐答案
答案是是,您转义了;
使用 ;;
:
The answer is yes, you escape ;
using ;;
:
/// <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-L400 ;另请参见下面的 Unescape
和 Parse
。)
(https://github.com/wixtoolset/wix3/blob/wix311rtm/src/DTF/Libraries/WindowsInstaller/customactiondata.cs#L391-L400; see also Unescape
and Parse
right below.)
可能甚至更好的消息,您可以将数据作为原始字符串访问并完全控制其反序列化的方式:
Potentially even better news, you can access the data as a raw string and be in total control of how it is deserialized:
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;
}
}
这篇关于WIX自定义操作参数中的连接字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!