سؤال

لدي ملف MSI يتم إنشاؤه باستخدام Wxs 3.0.يشير MSI الخاص بي إلى إجراء مخصص لـ C#، تمت كتابته باستخدام الملف الجديد مشروع الإجراء المخصص لـ C#.

أريد تمرير وسيطة إلى msiexec يتم توجيهها إلى الإجراء المخصص الخاص بي - على سبيل المثال:

msiexec /i MyApp.msi ENVIRONMENT=TEST#

في ملف ‎.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["ENVIRONMENT"];

ولكن لا يبدو أن هذا يعمل.

كيف يمكنني الوصول إلى الخاصية التي قمت بتمريرها إلى 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"];

نصائح أخرى

وفقط للتأكد من اكتمالها. باستخدام طريقة وصفها جيريمي ليو، في بلوق فوق يسمح تتعلق بما يلي:

والدعوة:

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. انظر> وأ href = "http://blogs.claritycon.com/blogs/sajo_jacob/archive/2008/02/28/customactiondata-in-wix-with-deferred-custom-actions.aspx" يختلط = "نوفولو noreferrer" > هذا بلوق وظيفة للحصول على مناقشة حول كيفية الحصول على ما يجب القيام به حيال ذلك. (وهذا مثال على ذلك هو إجراء مخصص فبسكريبت، ولكنك لن تكون قادرا على استرداد القيمة من خلال جمع session.CustomActionData).

إذا كنا نتحدث عن Wix Sharp (وليس Wix العادي بعناصر XML الخاصة به)، فإن إضافة خاصية مخصصة يعد أمرًا سهلاً.كل ما عليك فعله هو الضبط خصائص الاستخدامات خاصية الإجراء المُدار الخاص بك.

على سبيل المثال، إذا كنت تريد إضافة خاصية مخصصة باسم "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