簡體   English   中英

如何在服務安裝之前在 wix 中執行自定義操作?

[英]How can I execute a custom action in wix just before service installation?

這是我的 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>

我之前所做的是將所有自定義操作的邏輯放在一個可執行文件中,然后調用該可執行文件,效果很好。 事實證明,WiX 在 Visual Studio 中提供了各種自定義操作項目,無需創建獨立的可執行文件,請參閱此處以獲取 James Schaffer 的一個很好的示例。

至於控制何時執行自定義操作,您可以通過在 *.wxs 文件的 InstallExecuteSequence 節點中添加一個條目來控制它,就像這樣...

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

... 其中CheckLogLevel是我的自定義操作,它被定向為在InstallServices操作之前運行。

mattyB 豎起大拇指。

為了更好地理解這個問題,我認為在 Orca 中查看 MSI 很重要。 Orca 是一款 MS 產品,可以查看 MSI 文件的生命周期。 它還允許您直接編輯 MSI 文件。

下面是安裝程序將按順序運行的“作業”的屏幕截圖。 mattyB 提到了“InstallServices”作業,我在下面的屏幕截圖中突出顯示了它。 我們需要確保我們的所有自定義操作都在此作業運行之前發生。 從這里開始,就像將“Custom”標記中的“Before”屬性設置為“InstallServices”值一樣簡單。

希望這有助於進一步揭開 WiX 的神秘面紗。

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM