WIX 使用 x64 安装 Windows 服务 [英] WIX install windows service with x64

查看:49
本文介绍了WIX 使用 x64 安装 Windows 服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不得不将我的项目更改为 x64,现在遵循 this 教程 我也尝试将我的 WIX 安装更改为 x64.但是 WIX 安装会尝试安装 Windows 服务.此服务使用 msiexec/i Setup.msi/L*V install.log 在 install.log 中引发以下异常:

I had to change my project to x64 and now following this tutorial I try to change my WIX installation to x64 also. But the WIX installation tries to install a windows service. This service throws the following exception in install.log with msiexec /i Setup.msi /L*V install.log:

System.Reflection.TargetInvocationException:调用目标导致异常.--->System.BadImageFormatException: 文件或程序集Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null"或者没有找到对它的依赖.试图加载格式错误的文件.

System.Reflection.TargetInvocationException: A call target caused an exception. ---> System.BadImageFormatException: The file or Assembly "Service, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" or a dependency on it was not found. An attempt was made to load a file with the wrong format.

在 SaveServiceConfigurationAction.CustomActions.SaveServiceConfiguration(Session session)
--- 内部异常批量监控结束---
bei System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
bei System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
在 Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)

at SaveServiceConfigurationAction.CustomActions.SaveServiceConfiguration(Session session)
--- End of internal exception batch monitoring ---
bei System.RuntimeMethodHandle.InvokeMethod(Object target, Object arguments, Signature sig, Boolean constructor)
bei System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object parameters, Object arguments)
bei System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object parameters, CultureInfo culture)
at Microsoft.Deployment.WindowsInstaller.CustomActionProxy.InvokeCustomAction(Int32 sessionHandle, String entryPoint, IntPtr remotingDelegatePtr)

CustomAction SaveServiceConfigurationAction 返回实际错误代码 1603(请注意,如果在沙箱内进行翻译,这可能不是 100% 准确)

CustomAction SaveServiceConfigurationAction returned actual error code 1603 (note this may not be 100% accurate if translation happened inside sandbox)

当我尝试使用 installutil.exe 安装此服务时,我遇到了类似的异常

When I try to install this service with installutil.exe I get a similar exception

System.BadImageFormatException: 文件或程序集Service.exe"被删除或者没有找到对它的依赖.试图加载格式错误的文件.

System.BadImageFormatException: The file or assembly "Service.exe" or a dependency on it was not found. An attempt was made to load a file with the wrong format.

但是如果我使用 Framework64\v4.0.30319\installutil.exe 可以毫无问题地安装服务.

But if I use Framework64\v4.0.30319\installutil.exe the service could be installed with no problem.

那么现在我的问题是:如何配置我的 WIX 项目以使用 Framework64 来安装服务?

So now my question: How do I configure my WIX project to use Framework64 to install the service?

我的 WIX 代码:

<Component Id="CMP_Service" Feature="Core">
            <File Source="$(var.Service.TargetPath)" KeyPath="yes">
              <fire:FirewallException Id="ServiceException" Name="Service Exception" Protocol="tcp" Port="[PORTProperty]" Scope="any" />
            </File>
            <ServiceInstall Id="ServiceInstallELS"
                            Name="Service"
                            Description="..."
                            Start="auto"
              Account="[SERVICEACCOUNT]"
                            ErrorControl="normal"
                            Type="ownProcess"
              Vital="no" />
            <ServiceControl Id="ServiceControllELS"
                            Name="Service"
                            Start="install"
                            Stop="both"
                            Remove="uninstall"
                            Wait="no" />
          </Component>

推荐答案

请检查这个.

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <?define DemoMarketingContacts.UI_TargetDir=$(var.DemoMarketingContacts.UI.TargetDir)?>
  <?define DemoMarketingContacts.UploaderUI_TargetDir=$(var.DemoMarketingContacts.UploaderUI.TargetDir)?>
  <?define DemoMarketingContacts.ValidatorUI_TargetDir=$(var.DemoMarketingContacts.ValidatorUI.TargetDir)?>
  <?define DemoMarketingContacts.Domain_TargetDir=$(var.DemoMarketingContacts.Domain.TargetDir)?>
  <?define QueryStringUtilies_TargetDir=$(var.QueryStringUtilies.TargetDir)?>
  <?define Demo.InternetCheckerService_TargetDir=$(var.Demo.InternetCheckerService.TargetDir)?>
  <?define Demo.InternetChecker.Server_TargetDir=$(var.Demo.InternetChecker.Server.TargetDir)?>
  
  <Product Id="50D6E335-B3EF-44EE-B3AE-899B260F8FBF" Name="Demo Marketing Contacts" Language="1033" Version="4.0.0.0" 
           Manufacturer="Demo Technologies (pvt)Ltd." UpgradeCode="495757a4-415c-4dbe-81fb-a6fa78c40a5b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

    <Icon Id="EmailMarketing.ico" SourceFile="$(var.ProjectDir)Email Marketing.ico" />
    <Icon Id="UploadEmail.ico" SourceFile="$(var.ProjectDir)UploadEmail.ico" />
    <Icon Id="ValidEmail.ico" SourceFile="$(var.ProjectDir)ValidEmail.ico" />
    
    <Property Id="AppIcon" Value="Email Marketing" />
    <Property Id="ARPPRODUCTICON" Value="EmailMarketing.ico" />

    <!--<UIRef Id="WixUI_Minimal" />-->
    <UIRef Id="DemoSetUpUI" />

    <MajorUpgrade DowngradeErrorMessage="A newer version of [ProductName] is already installed."  />
    
    <MediaTemplate EmbedCab="yes" />

    <Feature Id="ProductFeature" Title="DemoMarketing Contacts" Level="1" TypicalDefault="install">
      <ComponentGroupRef Id="ProductComponents" />
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
      <ComponentRef Id="AuditLogFolderComponent" />
      <ComponentRef Id="LogFolderComponent" />
    </Feature>    
    <Feature Id="ValidatorFeature" Title="DemoMarketing Contacts Validator" Level="1" TypicalDefault="install">
      <ComponentGroupRef Id="ValidatorUIComponents" />
      <ComponentRef Id="ApplicationShortcut" />
      <ComponentRef Id="ApplicationShortcutDesktop" />
    </Feature>
    
    <Feature Id="InternetCheckerServiceFeature" Title="Demo Internet Checker" Level="2" Description="This is the Demo Internet Checker Service component" TypicalDefault="advertise">
      <ComponentGroupRef Id="ServiceComponetGroup" />
    </Feature>

  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="Demo Marketing Contacts">
          <Directory Id="AuditLogFolder" Name="AuditLog" />
          <Directory Id="LogFolder" Name="Log" />
        </Directory>
      </Directory>
      <Directory Id="ProgramMenuFolder">
        <Directory Id="ApplicationProgramsFolder" Name="DemoMarketing Contacts" />
      </Directory>
      <Directory Id="DesktopFolder" Name="Desktop" />
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="ApplicationProgramsFolder">
      <Component Id="ApplicationShortcut" Guid="A65731C2-FDFB-4C41-BD8B-8AD5E2E441B2">        
        <Shortcut Id="UploaderStartMenuShortcut" Name="DemoMarketing Contacts Uploader" Description="DemoMarketing Contacts Uploader" Target="[#DemoMarketingContacts.UploaderUI.exe]" WorkingDirectory="INSTALLFOLDER" />
        <Shortcut Id="ValidatorStartMenuShortcut" Name="DemoMarketing Contacts Validator" Description="DemoMarketing Contacts Validator" Target="[#DemoMarketingContacts.ValidatorUI.exe]" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveApplicationProgramsFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\DemoMarketing Contacts" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
    <DirectoryRef Id="DesktopFolder">
      <Component Id="ApplicationShortcutDesktop" Guid="6F764DEA-E1DE-418E-9B5C-4E09E6C5FB3E">
        
        <Shortcut Id="UploaderDesktopShortcut" Name="DemoMarketing Contacts Uploader" Description="DemoMarketing Contacts Uploader" Target="[#DemoMarketingContacts.UploaderUI.exe]" WorkingDirectory="INSTALLFOLDER" />
        <Shortcut Id="ValidatorDesktopShortcut" Name="DemoMarketing Contacts Validator" Description="DemoMarketing Contacts Validator" Target="[#DemoMarketingContacts.ValidatorUI.exe]" WorkingDirectory="INSTALLFOLDER" />
        <RemoveFolder Id="RemoveDesktopFolder" Directory="ApplicationProgramsFolder" On="uninstall" />
        <RegistryValue Root="HKCU" Key="Software\DemoMarketing Contacts" Name="installed" Type="integer" Value="1" KeyPath="yes" />
      </Component>
    </DirectoryRef>
    <DirectoryRef Id="AuditLogFolder">
      <Component Id="AuditLogFolderComponent" Guid="49FE9EB9-90A5-46D6-93FD-45FA153F53D5" KeyPath="yes">
        <CreateFolder />
      </Component>
    </DirectoryRef>
    <DirectoryRef Id="LogFolder">
      <Component Id="LogFolderComponent" Guid="B7CFA16B-B755-42F5-B9FE-AC161F758D53" KeyPath="yes">
        <CreateFolder />
      </Component>
    </DirectoryRef>
  </Fragment>

  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">

      <Component Id="DemoMarketingContacts.UploaderUI.exe" Guid="25B57A38-AD92-430E-96C0-887F7826E69E">
        <File Id="DemoMarketingContacts.UploaderUI.exe" Name="DemoMarketingContacts.UploaderUI.exe" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)DemoMarketingContacts.UploaderUI.exe" />
      </Component>

      <Component Id="DemoMarketingContacts.UploaderUI.exe.config" Guid="0DD136DB-D607-42F1-9FB6-24200E43AA80">
        <File Id="DemoMarketingContacts.UploaderUI.exe.config" Name="DemoMarketingContacts.UploaderUI.exe.config" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)DemoMarketingContacts.UploaderUI.exe.config" />
      </Component>
      
      <Component Id="MySql.Data.dll" Guid="1cd1c916-b9cc-451d-be2f-c17bec362710">
        <File Id="MySql.Data.dll" Name="MySql.Data.dll" Source="$(var.DemoMarketingContacts.UI_TargetDir)MySql.Data.dll" />
      </Component>
      <Component Id="DbManagerLibrary.dll" Guid="8307fa02-f630-4f0b-9ca1-77784fcc716b">
        <File Id="DbManagerLibrary.dll" Name="DbManagerLibrary.dll" Source="$(var.DemoMarketingContacts.UI_TargetDir)DbManagerLibrary.dll" />
      </Component>

      <Component Id="Md5CryptoEngine.dll" Guid="0baf14db-3d30-4f20-913d-9bba02357d63">
        <File Id="Md5CryptoEngine.dll" Name="Md5CryptoEngine.dll" Source="$(var.DemoMarketingContacts.UI_TargetDir)Md5CryptoEngine.dll" />
      </Component>
      <Component Id="QueryStringUtilies.dll" Guid="fdf2e586-a590-4ca8-bd4b-ef0fcafcd8e5">
        <File Id="QueryStringUtilies.dll" Name="QueryStringUtilies.dll" Source="$(var.QueryStringUtilies_TargetDir)QueryStringUtilies.dll" />
      </Component>

      <Component Id="DemoMarketingContacts.Domain.dll" Guid="719641ed-d882-412f-a826-ebded804de08">
        <File Id="DemoMarketingContacts.Domain.dll" Name="DemoMarketingContacts.Domain.dll" Source="$(var.DemoMarketingContacts.Domain_TargetDir)DemoMarketingContacts.Domain.dll" />
      </Component>
      <Component Id="Conf.sys" Guid="8f8f0b68-8a2f-4e6e-81b8-296b6d1e3038">
        <File Id="Conf.sys" Name="Conf.sys" Source="$(var.DemoMarketingContacts.UI_TargetDir)Conf.sys" />
      </Component>
      <Component Id="LicenseKey.sys" Guid="b5478971-d1d6-4d6c-b254-ded5d8658ef7">
        <File Id="LicenseKey.sys" Name="LicenseKey.sys" Source="$(var.DemoMarketingContacts.UI_TargetDir)LicenseKey.sys" />
      </Component>
      <Component Id="System.Windows.Interactivity.dll" Guid="1d71080d-a57b-47b9-9cbf-64f430252846">
        <File Id="System.Windows.Interactivity.dll" Name="System.Windows.Interactivity.dll" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)System.Windows.Interactivity.dll" />
      </Component>
      <Component Id="Caliburn.Micro.Platform.Core.dll" Guid="54fd8728-8a96-4d6e-bc14-2df25a47fbe5">
        <File Id="Caliburn.Micro.Platform.Core.dll" Name="Caliburn.Micro.Platform.Core.dll" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)Caliburn.Micro.Platform.Core.dll" />
      </Component>
      <Component Id="Cobisi.EmailVerify.Net45.dll" Guid="feb50857-53b2-4c14-904e-2f86f25fa4d8">
        <File Id="Cobisi.EmailVerify.Net45.dll" Name="Cobisi.EmailVerify.Net45.dll" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)Cobisi.EmailVerify.Net45.dll" />
      </Component>
      <Component Id="Caliburn.Micro.Platform.dll" Guid="c85997a8-0571-4a34-83cc-a12022f17ff7">
        <File Id="Caliburn.Micro.Platform.dll" Name="Caliburn.Micro.Platform.dll" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)Caliburn.Micro.Platform.dll" />
      </Component>
      <Component Id="Caliburn.Micro.dll" Guid="50795ece-887e-43bf-811f-29806c37ea5b">
        <File Id="Caliburn.Micro.dll" Name="Caliburn.Micro.dll" Source="$(var.DemoMarketingContacts.UploaderUI_TargetDir)Caliburn.Micro.dll" />
      </Component>
      <Component Id="Demo.InternetCheckerService.exe.config" Guid="c60abb1b-7f57-4056-86a6-23aa7cf936db">
        <File Id="Demo.InternetCheckerService.exe.config" Name="Demo.InternetCheckerService.exe.config" Source="$(var.Demo.InternetCheckerService_TargetDir)Demo.InternetCheckerService.exe.config" />
      </Component>
      <Component Id="Email_Marketing.ico" Guid="bbb37327-15e9-44ab-9816-c0bfe09a7895">
        <File Id="Email_Marketing.ico" Name="Email Marketing.ico" Source="$(var.DemoMarketingContacts.UI_TargetDir)Email Marketing.ico" />
      </Component>
      <Component Id="Read_me.txt" Guid="31685dd1-c56f-4c70-89a9-f2327d143f17">
        <File Id="Read_me.txt" Name="Read me.txt" Source="$(var.DemoMarketingContacts.UI_TargetDir)Read me.txt" />
      </Component>
     

    </ComponentGroup>   
    
    <ComponentGroup Id="ValidatorUIComponents" Directory="INSTALLFOLDER">
       <Component Id="DemoMarketingContacts.ValidatorUI.exe" Guid="8672B6FC-6419-495D-A9C3-F3977F8B7B8F">
        <File Id="DemoMarketingContacts.ValidatorUI.exe" Name="DemoMarketingContacts.ValidatorUI.exe" Source="$(var.DemoMarketingContacts.ValidatorUI_TargetDir)DemoMarketingContacts.ValidatorUI.exe" />
      </Component>  
      
      <Component Id="DemoMarketingContacts.ValidatorUI.exe.config" Guid="28572FF1-B8D8-42DF-86C8-041FFBA9EA31">
        <File Id="DemoMarketingContacts.ValidatorUI.exe.config" Name="DemoMarketingContacts.ValidatorUI.exe.config" Source="$(var.DemoMarketingContacts.ValidatorUI_TargetDir)DemoMarketingContacts.ValidatorUI.exe.config" />
      </Component>
    </ComponentGroup>
    
    <ComponentGroup Id="ServiceComponetGroup" Directory="INSTALLFOLDER">
      <Component Id="ServiceComponent" Guid="28ABD97D-3091-485D-AF21-0BD96151D52B" DiskId="1" SharedDllRefCount="no" KeyPath="no" NeverOverwrite="no" Permanent="no" Transitive="no" Win64="no" Location="either">
        <File Id="Demo.InternetChecker.Server.dll" Name="Demo.InternetChecker.Server.dll" Source="$(var.Demo.InternetChecker.Server_TargetDir)Demo.InternetChecker.Server.dll" KeyPath="no" />
        <File Id="Demo.InternetCheckerService.exe" Name="Demo.InternetCheckerService.exe" Source="$(var.Demo.InternetCheckerService_TargetDir)Demo.InternetCheckerService.exe" ReadOnly="no" Compressed="yes" KeyPath="yes" Vital="yes" Hidden="no" System="no" Checksum="no" />
        <ServiceInstall Id="DemoInternetCheckerServiceInstall" DisplayName="Demo Internet Checker Service Instance" Description="This Service is broadcast internet availability to the intranet." Name="DemoInternetCheckerExeName" ErrorControl="normal" Start="auto" Type="ownProcess" Vital="yes" />
        <ServiceControl Id="DemoInternetCheckerServiceControl" Name="DemoInternetCheckerExeName" Start="install" Stop="uninstall" Remove="uninstall" />

      </Component>
    </ComponentGroup>
  </Fragment>
</Wix>

这篇关于WIX 使用 x64 安装 Windows 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆