简体   繁体   English

WiX 3.8中的自定义操作

[英]Custom Actions in WiX 3.8

I have got problem with custom actions in my project. 我的项目中的自定义操作存在问题。 Some are working, some not. 有些在工作,有些没有。 I have got two projects C# CustomAction Project and Setup Project in VS 2012. My custom actions look like this. 在VS 2012中,我有两个项目C#CustomAction项目和Setup项目。我的自定义操作如下所示。 The two first actions are not causing the problem. 前两个动作没有引起问题。 Only the third one is not working. 只有第三个不起作用。

[CustomAction]
public static ActionResult WriteToConfigStore(Session session)
{
    ...
}

[CustomAction]
public static ActionResult CleanConfigStore(Session session)
{
    ...
}

[CustomAction]
public static ActionResult CheckPrograms(Session session)
{
    string s = "";

    Process[] p = Process.GetProcesses();

    foreach (Process ps in p)
    {
        s += ps.ProcessName + ";";
    }

    MessageBox.Show(s);

    return ActionResult.Success;
}

I defining custom actions like this: 我定义这样的自定义操作:

<Binary Id="CustomActionsId" SourceFile="$(var.ResourcesDir)\DriverCA.CA.dll" />
<CustomAction Id="ca_writeToConfigStoreId" BinaryKey="CustomActionsId" DllEntry="WriteToConfigStore" Execute="deferred" Return="check" />
<CustomAction Id="ca_cleanConfigStoreId" BinaryKey="CustomActionsId" DllEntry="CleanConfigStore" Execute="deferred" Return="check" />
<CustomAction Id="ca_setParameter" Return="check" Property="ca_writeToConfigStoreId" Value="param1=.;param2=;param3=;param4=;param5=IviDriver1.0, IviSwtch1.0" />
<CustomAction Id="ca_setCleanParameter" Return="check" Property="ca_cleanConfigStoreId" Value="param1=;" />
<CustomAction Id="ca_checkProgramsId" BinaryKey="CustomActionsId" DllEntry="CheckPrograms" Execute="deferred" Return="check" />

My install sequence is looking like this: 我的安装顺序如下所示:

<InstallExecuteSequence>
  <Custom Action="ca_setParameter" Before="InstallFinalize" />
  <Custom Action="ca_setCleanParameter" Before="InstallFinalize" />
  <!--Call only when not uninstall (install, change, repair)--> 
  <Custom Action="ca_writeToConfigStoreId" After="ca_setParameter">NOT(REMOVE="ALL")</Custom>
  <!--Call only when uninstall or upgrade--> 
  <Custom Action="ca_cleanConfigStoreId" After="ca_setCleanParameter">REMOVE="ALL"</Custom>
  <!--Call only when not install--> 
  <Custom Action="ca_checkProgramsId" After="MsiUnpublishAssemblies">Installed</Custom>
</InstallExecuteSequence>

When I comment <Custom Action="ca_checkProgramsId" After="MsiUnpublishAssemblies">Installed</Custom> everything works fine. 当我在<Custom Action="ca_checkProgramsId" After="MsiUnpublishAssemblies">Installed</Custom>评论<Custom Action="ca_checkProgramsId" After="MsiUnpublishAssemblies">Installed</Custom>一切正常。 But when this part is not commented out, then I got error There is problem with this Windows Installer package. A DLL required for this install to complete could not be run. 但是,如果没有对此部分进行注释,则会出现错误There is problem with this Windows Installer package. A DLL required for this install to complete could not be run. There is problem with this Windows Installer package. A DLL required for this install to complete could not be run. when uninstalling the program. 卸载程序时。 I can't see any error. 我看不到任何错误。 Every name and ID are correct. 每个名称和ID均正确。 I am not using PInvoke or anything like that. 我没有使用PInvoke或类似的东西。

UPDATE: The goal of custom action is to check if some processes are running or not and interrup uninstall process according to it. 更新:自定义操作的目标是检查某些进程是否正在运行,并根据其检查Interrup卸载进程。 Setup is per system and I didn't have problem problem with message boxes in any other custom actions. 设置是按系统进行的,其他任何自定义操作中的消息框都没有问题。 I solved it with another custom action project that have problem custom action in it by itself, but otherwise I am using exactly same methods and setup definitions (excluding another dll definition of course) Still don't know what the problem is. 我用另一个具有问题自定义操作的自定义操作项目解决了该问题,但是我使用的是完全相同的方法和设置定义(当然不包括另一个dll定义),但仍然不知道问题出在哪里。

A few things that might help: 一些可能会有所帮助的事情:

You may need privilege to enumerate processes on the system - I can't tell if your setup is per user (and therefore not elevated) or per system (and elevated through an elevation prompt). 您可能需要特权来枚举系统上的进程-我无法确定您的设置是按用户(因此未提升)还是按系统(并通过提升提示提升)。

I'm not sure that you can do a MessageBox.Show if the custom actions are elevated (and running with the system account) because exposing a Windows message loop to the desktop is a security hole. 我不确定是否可以执行MessageBox.Show自定义操作是否已提升(并使用系统帐户运行),因为将Windows消息循环暴露在桌面上是一个安全漏洞。

What do you think is the issue that after MsiPublishAssemblies is solving? 您认为MsiPublishAssemblies解决后的问题是什么? It's not obvious to me why you think that helps. 对我来说,你为什么认为有帮助还不是很明显。 I don't think it's related to the problem unless your code actually has a dependency on an assembly in the GAC because it won't be installed until InstallFinalize (which is what really matters, not publishing assemblies). 除非您的代码实际上依赖于GAC中的程序集,否则我认为这与问题无关,因为直到InstallFinalize(这才是真正的要紧,而不是发布程序集)才安装它。

Not a real answer, but hopefully more than a comment. 这不是一个真正的答案,但希望不仅仅是评论。

Debug harder: 调试困难:

  1. Simplify your CustomAction CheckPrograms to just set a dummy-property and return ActionResult.Success . 简化您的CustomAction CheckPrograms使其仅设置虚拟属性并返回ActionResult.Success Then run msiexec with verbose logging to see if you reached the code setting the property. 然后使用详细日志记录运行msiexec ,以查看是否到达设置属性的代码。
  2. If 1) does show the setting of the dummy-property, add either a) displaying a MessageBox with a static string, or b) enumerating the processes (possibly, in a next mini-step) putting some info of these enumerated processes into the dummy-property to see whether you get expected values. 如果1)确实显示了虚拟属性的设置,请添加a)显示带有静态字符串的MessageBox,或b)枚举进程(可能在下一个微型步骤中),将这些枚举进程的一些信息放入虚拟属性,以查看是否获得期望值。
  3. If 1) does not show the setting of the dummy-property, try integrating the simplified CustomAction at another point (or anything else you come up with). 如果1)没有显示虚拟属性的设置,请尝试在另一点(或您想到的其他任何东西)集成简化的CustomAction。

It all boils down to this: If you don't have any ideas regarding possible errors, try to simplify the offending code in differing areas, one by one . 归结为:如果您对可能的错误没有任何想法,请尝试在不同区域逐一简化有问题的代码

Provide more info: 提供更多信息:

  1. Did you simplify your question to illustrate the problem? 您是否简化了问题以说明问题? If so, does this simplified version still reproduce the error? 如果是这样,此简化版本是否仍会重现错误? (Eg a very important point is: Did you omit some CustomActions?) (例如,非常重要的一点是:您是否省略了一些CustomActions?)
  2. As a last resort, come up with a minimalistic example triggering the error and make it accessible somewhere. 作为最后的选择,拿出一个触发错误并使其可在某处访问的简单示例。 Maybe somebody looks at it. 也许有人看着它。

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

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