只是为了完整性;使用 Jeremy Lew 描述的方法,在上面的博客中允许以下内容:
来电:
msiexec /i ITP.Platform.2.msi ENVIRONMENT=QA CONFIGFILE=EnvironmentConfig.xml
在 .wxs 文件中使用这个:
<Property Id="ENVIRONMENT" Secure="yes" />
<Property Id="CONFIGFILE" Secure="yes" />
<Binary Id="Itp.Configurator.WixCustomAction.dll"
SourceFile="$(var.Itp.Configurator.WixCustomAction.Path)" />
<CustomAction Id="SetCustomActionDataValue"
Return="check"
Property="Itp.Configurator.WixCustomAction"
Value="[ENVIRONMENT],G2,[CONFIGFILE],[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" />
<CustomAction Id="Itp.Configurator.WixCustomAction"
Return="check"
Execute="deferred"
BinaryKey="Itp.Configurator.WixCustomAction.dll"
DllEntry="ConfigureItpBrandSettings" />
<InstallExecuteSequence>
<Custom Action="SetCustomActionDataValue" After="InstallFiles"></Custom>
<Custom Action="Itp.Configurator.WixCustomAction" After="SetCustomActionDataValue"></Custom>
</InstallExecuteSequence>
使用自定义操作:
/// <summary>
/// CustomAction keys should be Environment,BrandId,ConfigPath,itpBasePath
/// </summary>
/// <param name="session"></param>
/// <returns></returns>
[CustomAction]
public static ActionResult ConfigureItpBrandSettings(Session session)
{
string[] arguments = GetCustomActionDataArguments(session);
string environmentName = arguments[0];
string brandId = arguments[1];
string configPath = arguments[2];
string itpBasePath = arguments[3];
//Do stuff
return ActionResult.Success;
}
private static string[] GetCustomActionDataArguments(Session session)
{
string[] keys = new string[session.CustomActionData.Keys.Count];
session.CustomActionData.Keys.CopyTo(keys,0);
return keys[0].Split(',');
}
作品。
解析 CustomActionData 参数非常难看,但它确实有效。希望有人知道一种更优雅的方式来做到这一点。