¿Cómo paso propiedades msiexec a una acción personalizada de WiX C#?


Tengo un archivo MSI que se está creando con Wxs 3.0. Mi MSI hace referencia a una acción personalizada en C#, escrita usando el nuevo proyecto de Acción personalizada en C# .

Quiero pasar un argumento a msiexec que se enruta a mi acción personalizada, por ejemplo:

Msiexec /i MyApp.msi ENVIRONMENT = TEST #

En mi .archivo wxs, me refiero a mi acción personalizada como esta:

<Property Id="ENVIRONMENT"/>
<Binary Id="WixCustomAction.dll"  SourceFile="$(var.WixCustomAction.Path)" />
<CustomAction Id="WixCustomAction" BinaryKey="WixCustomAction.dll"    DllEntry="ConfigureSettings"/>
<InstallExecuteSequence>
   <Custom Action="WixCustomAction" After="InstallFiles"></Custom>
</InstallExecuteSequence>

Mi acción personalizada en C# se configura así:

[CustomAction]
public static ActionResult ConfigureSettings(Session session)
{

}

Esperaba poder acceder a la propiedad así:

String EnvironmentName = session.Property ["ENVIRONMENT"];

Pero esto no parece funcionar.

¿Cómo puedo acceder a la propiedad que pasé a msiexec en mi acción personalizada?

Author: Peter Mortensen, 2009-05-07

5 answers

Si en lugar de

<CustomAction Id="SetCustomActionDataValue"
              Return="check"
              Property="Itp.Configurator.WixCustomAction"
              Value="[ENVIRONMENT],G2,[CONFIGFILE],[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" />

Escribe esto:

<CustomAction Id="SetCustomActionDataValue"
              Return="check"
              Property="Itp.Configurator.WixCustomAction"
              Value="Environment=[ENVIRONMENT];G=G2;ConfigFile=[CONFIGFILE];TargetDir=[TARGETDIR]ITP_v$(var.VERSION_MAJOR)" />

Entonces podrá hacer referencia a sus variables de esta manera:

string env=session.CustomActionData["Environment"];
 30
Author: Tomasz Grobelny,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2013-06-21 10:33:53

Solo para completar; usando el método descrito por Jeremy Lew, en el blog anterior permite lo siguiente:

Llamando:

msiexec /i ITP.Platform.2.msi ENVIRONMENT=QA CONFIGFILE=EnvironmentConfig.xml

Con esto en el.archivo 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>

Con una acción personalizada:

    /// <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(',');
    }

Funciona.

Analizar los argumentos CustomActionData es bastante feo, pero funciona. Esperemos que alguien sepa una forma más elegante de hacer esto.

 14
Author: David Laing,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-16 11:07:12

Aquí está mi código de trabajo:

<Binary Id="MyCA" SourceFile="..\bin\ChainerRun.CA.exe" />

<CustomAction Id="SetCustomActionDataValue" Return="check" Property="CustomActionData" Value="TARGETDIR=[TARGETDIR];AA=Description;" />

<CustomAction Id="ReadAndSet" 
            BinaryKey="MyCA" 
            DllEntry="ReadAndSet" 
            Execute="immediate"
            HideTarget="no" 
            Return="check" />

<InstallExecuteSequence>
    <Custom Action="SetCustomActionDataValue" Before="InstallFiles" />
    <Custom Action="ReadAndSet" After="SetCustomActionDataValue" />
</InstallExecuteSequence>

En la función de acción personalizada de C#:

[CustomAction]
public static ActionResult ReadAndSet(Session session)
{
    ActionResult retCode = ActionResult.NotExecuted;

    System.Diagnostics.Debug.Assert(false);

    session.Log("ReadAndSet() begins ...");

    string installLocation = session.CustomActionData["TARGETDIR"];
    string hostName = session.CustomActionData["AA"];
    ...
}
 8
Author: Ben,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2014-12-09 10:11:51

Su acción personalizada debe ser una acción personalizada diferida para poder ejecutarse después de InstallFiles. Las acciones personalizadas diferidas no tienen acceso a las propiedades, pero sí a CustomActionData. Ver esta entrada del blog para una discusión sobre cómo obtener qué hacer al respecto. (Este ejemplo es una acción personalizada de VBScript, pero podrá recuperar el valor a través de la sesión.Colección CustomActionData.)

 8
Author: jlew,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2015-12-17 09:29:34

Si estamos hablando de Wix Sharp (y no de Wix simple con sus cosas XML), agregar una propiedad personalizada es pan comido. Todo lo que tiene que hacer es establecer la propiedad UsesProperties para su acción administrada.

Por ejemplo, si desea agregar una propiedad personalizada llamada " MYPROP ", simplemente defina su acción de la siguiente manera:

new ElevatedManagedAction(nameof(CustomActions.MyCustomAction))
{
    Condition = Condition.Installed,
    When = When.Before,
    Step = Step.RemoveFiles,
    Return = Return.check,
    Execute = Execute.deferred,
    UsesProperties = "MYPROP"
}

Establezca el valor de la propiedad a través de la línea de comandos msiexec:

msiexec /i my.msi MYPROP=MYVALUE

Y entonces usted será capaz de acceder a ella desde su costumbre medidas:

[CustomAction]
public static ActionResult MyCustomAction(Session session)
{
    session.Log("MYPROP VALUE: " + session.CustomActionData["MYPROP"]);
    return ActionResult.Success;
}

Cuando la propiedad no se establece a través de la línea de comandos, el valor predeterminado será una cadena vacía.

 0
Author: Funbit,
Warning: date(): Invalid date.timezone value 'Europe/Kyiv', we selected the timezone 'UTC' for now. in /var/www/agent_stack/data/www/ajaxhispano.com/template/agent.layouts/content.php on line 61
2016-08-30 09:22:35