如何在服务安装之前在wix中执行自定义操作?

时间:2014-03-20 06:22:20

标签: wix custom-action

这是我的Product.wxs:

在自定义操作中,我想在安装Apache 2.4服务之前在httpd.conf文件中进行更改,实际上Apache 2.4服务从httpd.conf获取配置参数,因此对于应该更改的代码必须是在安装服务之前制作,如果有任何想法可以帮助我吗?

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi" xmlns:util='http://schemas.microsoft.com/wix/UtilExtension'>

  <Product Id="*" Name="MyExampleProject" Language="1033" Version="1.0.0.0" Manufacturer="Mq" UpgradeCode="08bd3c48-deef-4370-ab94-f8b4d49406e3">
        <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" InstallPrivileges="elevated"/>

        <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed." />
        <MediaTemplate />           
<!--System Configuration Condition - Installation install only above Windows XP-->

    <Condition Message="This application is only supported on Windows XP, or higher.">
      <![CDATA[Installed OR (VersionNT >= 501)]]>
    </Condition>

    <Directory Id='TARGETDIR' Name='SourceDir'>
      <Directory Id='ProgramFilesFolder' Name='PFiles'>
          <Directory Id='INSTALLDIR' Name='AgentFramework'>
            <Directory Id='INSTALLBIN' Name='bin'/>
                <Directory Id='INSTALLCONF' Name='conf'/>
            <Directory Id='INSTALLMODULES' Name='modules'/>
            </Directory>
        </Directory>
      </Directory>
    <Feature
     Id = "ProductFeature1"
     Title  = "AgentFramework"
     Level  = "1"
     Absent="allow">

      <ComponentRef Id='libapr_dll'/>
      <ComponentRef Id='libapriconv_dll'/>
      <ComponentRef Id='libaprutil_dll'/>
      <ComponentRef Id='libhttpd_dll'/>
      <ComponentRef Id='Pcre_dll'/>
      <ComponentRef Id='Configurationfile'/>
      <ComponentRef Id='Authzmodule'/>
      <ComponentRef Id='Dirmodule'/>
      <ComponentRef Id='ServiceComponent'/>
    </Feature>    

    <DirectoryRef Id='INSTALLCONF'>
      <Component Id='Configurationfile' Guid='2E0D2957-10EB-463A-A4FC-62B9062FE8A3'>
        <File Id='Configurationfile' Name='httpd.conf' DiskId='1' Source='$(sys.CURRENTDIR)\httpd.conf' KeyPath='yes'>
        </File>
      </Component>
    </DirectoryRef>
    <DirectoryRef Id='INSTALLMODULES'>
      <Component Id='Authzmodule' Guid='62AA97B6-7821-4CB4-9F89-B2A8FF0CC6BD'>
        <File Id='Authzmodule' Name='mod_authz_core.so' DiskId='1' Source='$(sys.CURRENTDIR)\mod_authz_core.so' KeyPath='yes'>
        </File>
      </Component>
      <Component Id='Dirmodule' Guid='9966BB3B-8296-43B9-A6DC-712561303329'>
        <File Id='Dirmodule' Name='mod_dir.so' DiskId='1' Source='$(sys.CURRENTDIR)\mod_dir.so' KeyPath='yes'>
        </File>
      </Component>
    </DirectoryRef>
    <DirectoryRef Id='INSTALLBIN'>
      <Component Id='libapr_dll' Guid='FB82D093-0B32-465B-8D8B-08B3127EB414'>
        <File Id='libapr_dll' Name='libapr-1.dll' DiskId='1' Source='$(sys.CURRENTDIR)\libapr-1.dll' KeyPath='yes'>
        </File>
      </Component>
      <Component Id='libapriconv_dll' Guid='667D6D5B-6FE4-4A6B-827F-C496239628E2'>
        <File Id='libapriconv_dll' Name='libapriconv-1.dll' DiskId='1' Source='$(sys.CURRENTDIR)\libapriconv-1.dll' KeyPath='yes'>
        </File>
      </Component>
      <Component Id='libaprutil_dll' Guid='72C688D2-8E25-49D9-9E76-F6BDBC33D394'>
        <File Id='libaprutil_dll' Name='libaprutil-1.dll' DiskId='1' Source='$(sys.CURRENTDIR)\libaprutil-1.dll' KeyPath='yes'>
        </File>
      </Component>
      <Component Id='libhttpd_dll' Guid='8946D5B1-0EA2-443E-8C20-CD8D877ACF75'>
        <File Id='libhttpd_dll' Name='libhttpd.dll' DiskId='1' Source='$(sys.CURRENTDIR)\libhttpd.dll' KeyPath='yes'>
        </File>
      </Component>
      <Component Id='Pcre_dll' Guid='0466BB2A-137C-4A95-A510-43E7A274F834'>
        <File Id='Pcre_dll' Name='pcre.dll' DiskId='1' Source='$(sys.CURRENTDIR)\pcre.dll' KeyPath='yes'>
        </File>
      </Component>
      <Component Id ="ServiceComponent" Guid="8A1BF3F0-8A84-456E-816A-5907B40B2DDB" >
        <File Id='Applicationfile' Name='httpd.exe' DiskId='1' Source='$(sys.CURRENTDIR)\httpd.exe' KeyPath='yes'>
        </File>
        <ServiceInstall Id="ServiceComponent" Type="ownProcess" Name="Apache2.4"
                        DisplayName="Apache2.4" Description="Service" 
                        Arguments="-k runservice" Start="auto"  Account="LocalSystem" ErrorControl="normal" 
                        Vital="yes" > 
          <util:PermissionEx  User="Everyone" ServicePauseContinue="yes" ServiceQueryStatus="yes"
                              ServiceStart="yes" ServiceStop="yes" ServiceUserDefinedControl="yes" /> </ServiceInstall>


        <ServiceControl Id="ServiceComponent" Start="install" Stop="both"
                                Remove="uninstall" Name="Apache2.4" Wait="yes" />
      </Component>
    </DirectoryRef>
    <UIRef Id="CustomizeDlg" />

    <UI Id="MyWixUI_Mondo">
      <UIRef Id="WixUI_Mondo" />
      <UIRef Id="WixUI_ErrorProgressText" />

      <DialogRef Id="UserRegistrationDlg" />


      <Publish Dialog="LicenseAgreementDlg" Control="Next" Event="NewDialog" Value="UserRegistrationDlg" Order="3">LicenseAccepted = "1"</Publish>
      <Publish Dialog="SetupTypeDlg" Control="Back" Event="NewDialog" Value="UserRegistrationDlg">1</Publish>
    </UI>
    <Property Id="PIDTemplate"><![CDATA[1234<####-####-####-####>@@@@]]></Property>

    <CustomAction Id='CheckLogLevel' BinaryKey='CheckLogLevel' DllEntry='CustomAction1' />
    <Binary Id ='CheckLogLevel' SourceFile='$(sys.CURRENTDIR)\MqAgent_LogLevel.dll'/>
    <WixVariable Id="WixUIBannerBmp" Value="C:\Image\style39_banner.bmp" />
    <WixVariable Id="WixUIDialogBmp" Value="C:\Image\style39_dialog.bmp" />
    </Product>
</Wix>

这里是CustomizeDlg.wxs:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Fragment>
    <UI Id ="CustomizeDlg">
      <ComboBox Property="SETUPLOGLEVEL">

        <ListItem Text="Debug" Value="1" />

        <ListItem Text="info" Value="2" />

        <ListItem Text="warn" Value="3" />

      </ComboBox>
      <Dialog Id="UserRegistrationDlg" Width="370" Height="270" Title="[ProductName] Setup" NoMinimize="yes">
        <Control Id="NameEdit" Type="ComboBox" X="52" Y="48" Width="156" Height="10" ComboList="yes"
          Property="SETUPLOGLEVEL" Sorted="no" RightToLeft="yes"/>
        <Control Id="CDKeyLabel" Type="Text" X="45" Y="147" Width="50" Height="10" TabSkip="no">
          <Text>CD &amp;Key:</Text>
        </Control>
        <Control Id="CDKeyEdit" Type="MaskedEdit" X="45" Y="159" Width="250" Height="16" Property="PIDKEY" Text="[PIDTemplate]" />
        <Control Id="Back" Type="PushButton" X="180" Y="243" Width="56" Height="17" Text="&amp;Back">
          <Publish Event="NewDialog" Value="LicenseAgreementDlg">1</Publish>
        </Control>
        <Control Id="Cancel" Type="PushButton" X="304" Y="243" Width="56" Height="17" Cancel="yes" Text="Cancel">
          <Publish Event="SpawnDialog" Value="CancelDlg">1</Publish>
        </Control>
        <Control Id="BannerBitmap" Type="Bitmap" X="0" Y="0" Width="370" Height="44" TabSkip="no" Text="WixUI_Bmp_Banner" />
        <Control Id="Description" Type="Text" X="25" Y="23" Width="280" Height="15" Transparent="yes" NoPrefix="yes">
          <Text>Please mention the log level</Text>
        </Control>
        <Control Id="BottomLine" Type="Line" X="0" Y="234" Width="370" Height="0" />
        <Control Id="Title" Type="Text" X="15" Y="6" Width="200" Height="15" Transparent="yes" NoPrefix="yes">
          <Text>{\WixUI_Font_Title}Select Log Level</Text>
        </Control>
        <Control Id="BannerLine" Type="Line" X="0" Y="44" Width="370" Height="0" />
      </Dialog>
    </UI>
  </Fragment>
</Wix>

2 个答案:

答案 0 :(得分:1)

之前我所做的是将所有自定义操作的逻辑放在可执行文件中,然后调用可执行文件,该文件运行良好。事实证明,WiX在Visual Studio中提供了各种自定义动作项目,无需创建独立的可执行文件,请参阅here以获得James Schaffer的一个很好的例子。

至于控制何时执行自定义操作,您可以通过在* .wxs文件的InstallExecuteSequence节点中添加一个条目来控制它,就像这样......

<InstallExecuteSequence>
  <Custom Action="CheckLogLevel"  Before="InstallServices" />
</InstallExecuteSequence>

...其中CheckLogLevel是我的自定义操作,并且它被指示在InstallServices操作之前运行。

答案 1 :(得分:0)

mattyB 竖起大拇指。

为了更好地理解这个问题,我认为在 Orca 中查看 MSI 很重要。 Orca 是一款 MS 产品,可以查看 MSI 文件的生命周期。它还允许您直接编辑 MSI 文件。

以下是安装程序按顺序运行的“作业”的屏幕截图。 mattyB 提到了“InstallServices”作业,我在下面的屏幕截图中突出显示了它。我们需要确保我们的所有自定义操作都在此作业运行之前发生。从这里开始,就像将“Custom”标签中的“Before”属性设置为“InstallServices”一样简单。

希望这有助于进一步揭开 WiX 的神秘面纱。

enter image description here