문제

WXS 3.0으로 MSI 파일이 생성됩니다. My MSI는 새로운 The New를 사용하여 작성된 C# 사용자 정의 액션을 참조합니다. C# 사용자 정의 액션 프로젝트.

예를 들어 내 사용자 지정 조치로 라우팅되는 MSIEXEC에 인수를 전달하고 싶습니다.

msiexec /i myapp.msi 환경 = 테스트#

.wxs 파일에서 다음과 같은 사용자 정의 조치를 참조하십시오.

<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>

내 C# 사용자 정의 작업은 다음과 같이 설정됩니다.

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

}

나는 다음과 같은 부동산에 액세스 할 수있을 것으로 기대했다.

문자열 환경 이름 = session.property [ "환경"];

그러나 이것은 작동하지 않는 것 같습니다.

사용자 정의 조치에서 MSIEXEC에 전달한 속성에 어떻게 액세스합니까?

도움이 되었습니까?

해결책

대신

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

당신은 이것을 씁니다 :

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

그런 다음 변수를 다음과 같이 참조 할 수 있습니다.

string env=session.CustomActionData["Environment"];

다른 팁

완전성을 위해서만; 위의 블로그에서 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 인수를 구문 분석하는 것은 매우 추악하지만 작동합니다. 바라건대 누군가가 더 우아한 방법을 알고 있기를 바랍니다.

내 작업 코드는 다음과 같습니다.

<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>

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"];
    ...
}

InstallFiles 이후에 실행하려면 사용자 정의 작업이 연기 된 사용자 정의 작업이어야합니다. 지연된 사용자 정의 작업은 속성에 액세스 할 수 없지만 CustomActionData에 액세스 할 수 있습니다. 보다 이 블로그 게시물 그것에 대해 무엇을 해야하는지에 대한 토론을 위해. (이 예제는 vbscript 사용자 정의 조치이지만 세션을 통해 값을 검색 할 수 있습니다.

우리가 Wix Sharp (XML 물건이있는 일반 Wix가 아닌)에 대해 이야기하고 있다면 사용자 정의 속성을 추가하는 것은 케이크 조각입니다. 당신이해야 할 일은 설정하기 만하면됩니다 useproperties 관리 조치에 대한 속성.

예를 들어, "이름이 지정된 사용자 정의 속성을 추가하려면"MyProp", 당신의 행동을 다음과 같이 정의하십시오.

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

MSIEXEC 명령 줄을 통해 속성 값을 설정하십시오.

msiexec /i my.msi MYPROP=MYVALUE

그런 다음 사용자 정의 액션에서 액세스 할 수 있습니다.

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

명령 줄을 통해 속성을 설정하지 않으면 기본값은 빈 문자열입니다.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top