简体   繁体   English

WiX安装程序在静音和“正常”模式下启动相同的自定义操作

[英]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. 我需要创建一个设置来启动自定义操作,配置一些SQL的东西。

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. 重要的部分是if-block。 For testing purposes i want to create a file and write "Test" in it when the installer is silently executed. 出于测试目的,我想创建一个文件,并在静默执行安装程序时在其中写入“Test”。 According to Microsoft the UILevel property should be 2. https://msdn.microsoft.com/en-us/library/windows/desktop/aa372096(v=vs.85).aspx 据微软称,UILevel属性应为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. 我访问了http://wixtoolset.org/documentation/manual/v3/customactions/qtexec.html ,看到你可以在自定义动作标签中使用DllEntry =“WixSilentExec”,但据我所知,DLL条目的名称是您的自定义操作方法。 In my case ShowInitialForm. 在我的例子中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." 该日志长达1700行,偶然我发现导致安装失败的错误是错误1925,这意味着“您没有足够的权限为该机器的所有用户完成此安装。以管理员身份登录然后重试这个装置。“

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. 您在二进制元素中引用(您的自定义操作项目).CA.dll You should refer to (your custom action project).dll instead. 您应该参考(您的自定义操作项目).dll

Basing on your custom action placement, it should be a deferred type CA, but you are using an immediate type CA. 根据您的自定义操作位置,它应该是延迟类型CA,但您使用的是直接类型CA. Immediate CA will not be called at this time. 此时不会立即调用直接CA. 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: 这样做是为了将数据传递给您的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: 应该定义在执行序列中的StartCustomAction之前调用SetProperty.StartCustomAction CA:

<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. 使用PhilDW建议并始终使用日志输出运行。 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. 使用命令行msiexec / I [msi的路径] / l * vx [文本日志文件的路径]安装,看看发生了什么。 It will show the value of the UILevel property. 它将显示UILevel属性的值。 In addition, the log will tell you if the install attempted to call your Dll at all. 此外,日志将告诉您安装是否尝试完全调用您的Dll。 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). session.log调用作为代码中的第一件事将告诉您代码是否已启动(您的文本将出现在该MSI日志中)。 Do as many session.log calls as required to see if and where it fails. 根据需要执行尽可能多的session.log调用,以查看它是否失败以及失败的位置。

You cannot assume that it can't find the Dll because the issue could be a missing dependent Dll. 您不能假设它找不到Dll,因为问题可能是缺少依赖Dll。 The png file you posted with the Dlls shown - it's not clear what that is intended to show. 您在显示Dll时发布的png文件 - 目前尚不清楚要显示的内容。 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. Dll位于MSI文件的二进制表中,并将流式传输到将被调用的某个位置,因此根据定义,它们不会丢失。 Dlls in the Binary table are not "installed" to be called as CAs - they are streamed out, called, then removed. 二进制表中的Dll未被“安装”以被称为CA - 它们被流式传输,调用,然后被移除。 It's not obvious that the png file shows that temporary location. png文件显示临时位置并不明显。 There is some layering in the WiX/DTF method of calling managed code custom actions, maybe you were looking in the wrong place. 在调用托管代码自定义操作的WiX / DTF方法中有一些分层,也许你看错了地方。

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. 希望您的对话框能够在WiX / DTF托管代码自定义操作体系结构中工作,因为您需要在具有功能消息循环的STA窗口线程中。 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). 从架构上讲,这些数据应该在开始时在UI中收集,如果UI被抑制,那么在UI中设置的属性值可以通过msiexec命令行传递,因此安装仍然可以完成所有操作(并且您需要没有UILevel检查)。 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. 另一个常见的替代方法是在第一次使用应用程序时运行该程序,因为您正在运行一个普通的,可调试UI的可测试程序。 As another alternative, just run an actual program as an exe custom action, and again this is a normal UI program, testable, debuggable etc. 作为另一种选择,只需将实际程序作为exe自定义操作运行,这也是一个普通的UI程序,可测试,可调试等。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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