简体   繁体   中英

WiX Setup launching same custom action in silent and “normal” mode

I need to create a setup to launch a custom action which configures some SQL stuff.

This is my sequence:

<InstallExecuteSequence>
  <Custom Action='StartCustomAction' After='InstallFinalize'>NOT Installed</Custom>
</InstallExecuteSequence>

Here i call my custom action:

<Fragment>
  <Binary Id="CustomActionBinary" SourceFile="$(var.InfPro.dotigaRuntimeSetup.CustomActions.TargetDir)$(var.InfPro.dotigaRuntimeSetup.CustomActions.TargetName).CA.dll"/>
  <CustomAction Id="StartCustomAction" BinaryKey="CustomActionBinary" DllEntry="ShowInitialForm" Execute="immediate" Return="check"/>
</Fragment>

This is my custom action:

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

   int i = Convert.ToInt32(session["UILevel"]);
   if (i == 2)
   {
       StreamWriter file = new StreamWriter("c:\test.txt");
       file.WriteLine("Test");

       file.Close();
        }
   else { 
       InitialForm f = new InitialForm();
       if (f.ShowDialog() == DialogResult.Cancel)
          return ActionResult.UserExit;
       }
       return ActionResult.Success; 
}

The important section is the if-block. For testing purposes i want to create a file and write "Test" in it when the installer is silently executed. According to Microsoft the UILevel property should be 2. https://msdn.microsoft.com/en-us/library/windows/desktop/aa372096(v=vs.85).aspx

Unfortunately NOTHING happens. I don't even know if the custom action gets called.

I visited http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html and saw that you can use DllEntry="WixSilentExec" in the custom action tag but as far as i know the DLL entry is the name of your custom action method. In my case ShowInitialForm.

Thanks for your help. ;)

Thanks for all your help but the solution went in the complete other way. I called my setup in quiet mode using following command:

msiexec /i mySetup.msi /l*v myLog.log 

The log is 1700 lines long and by accident I found that the error which caused the setup to fail was error 1925 which means "You do not have sufficient privileges to complete this installation for all users of the machine. Log on as administrator and then retry this installation."

So I launched the setup as admin via the command line and everything worked fine.

You refer to (your custom action project).CA.dll in the Binary element. You should refer to (your custom action project).dll instead.

Basing on your custom action placement, it should be a deferred type CA, but you are using an immediate type CA. Immediate CA will not be called at this time. Change your action type to deferred. Pay your attention that deferred actions cannot access session variables. Do like this to pass data to your CA:

<CustomAction Id="SetProperty.StartCustomAction" Property="StartCustomAction" Value="UILevel=[UILevel]" />
<CustomAction Id="StartCustomAction" BinaryKey="CustomActionBinary" DllEntry="ShowInitialForm" Execute="deferred" />

The SetProperty.StartCustomAction CA should be defined to be called before StartCustomAction in execute sequence:

<Custom Action='SetProperty.StartCustomAction' After='InstallFinalize'>NOT Installed</Custom>
<Custom Action='StartCustomAction' After='SetProperty.StartCustomAction'>NOT Installed</Custom>

Inside your action code use this code to access the passed value:

session.CustomActionData["UILevel"]

Use PhilDW advice and always run with log output. Use code like this to write to log your debug output:

session.Log("Begin ShowInitialForm CustomAction");

Hope this helps.

Install with a command line msiexec /I [path to msi] /l*vx [path to text log file] to see what's going on. It will show the value of the UILevel property. In addition, the log will tell you if the install attempted to call your Dll at all. A session.log call as the first thing in your code will tell you if the code started (your text will appear in that MSI log). Do as many session.log calls as required to see if and where it fails.

You cannot assume that it can't find the Dll because the issue could be a missing dependent Dll. The png file you posted with the Dlls shown - it's not clear what that is intended to show. The Dlls are in the Binary table of the MSI file and will be streamed out to some location where they will be called, so by definition, they cannot be missing. Dlls in the Binary table are not "installed" to be called as CAs - they are streamed out, called, then removed. It's not obvious that the png file shows that temporary location. There is some layering in the WiX/DTF method of calling managed code custom actions, maybe you were looking in the wrong place.

Hopefully your dialog will work in the WiX/DTF managed code custom action architecture because you need to be in a STA windows thread with a functional message loop. Architecturally, this data should be collected in the UI at the start, and if the UI is suppressed then the property values that would have been set in the UI can be passed via the msiexec command line so the install still does everything (and you need no UILevel checking). Another common alternative is to run the program the first time the app is used because you are then running a normal, UI debuggable, testable program. As another alternative, just run an actual program as an exe custom action, and again this is a normal UI program, testable, debuggable etc.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM