如何在wiX项目中添加自定义操作

问题描述

这就是我所做的。

CustomAction类。它成功构建。

     public class ActionClass
    {
        [CustomAction]
        public static ActionResult MySimpleAction(Session session)
        {
            try
            {
                File.Create(@"D:\file.txt");

            }

            catch (Exception)
            {
                return ActionResult.Failure;
            }
            return ActionResult.Success;
        }
    } 

Product.wxs

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <!-- Give Product a Unique id per Platform -->
  <?if $(var.Platform)=x64 ?>
  <?define ProductCode = "{4A557D39-F478-4906-AA21-A199EB304074}"  ?>
  <?else?>
  <?define ProductCode = "{7BBB7D08-E682-41C7-A1D3-F37CF09ED101}"  ?>
  <?endif?>

  <!-- Fixed Upgrade ID -->
  <?define UpgradeCode = "{EF7689A2-D62B-486A-AF2A-AC7CD1212649}"  ?>
  <?define BuildVersion = 1.0.0.0 ?>
  
  <!-- Define main Product -->
    <Product Id="$(var.ProductCode)" 
    Name="!(loc.ProductName_$(var.Platform))" 
    Language="!(loc.Language)" 
    Version="$(var.BuildVersion)" 
    Manufacturer="!(loc.Company)" 
    UpgradeCode="$(var.UpgradeCode)">

    
    
    <!-- Provide Package detail -->
        <Package 
      InstallerVersion="200" 
      Compressed="yes" 
      InstallScope="perMachine" 
      Platform="$(var.Platform)"
      Manufacturer="!(loc.Company)"
      Description="!(loc.Description)"
      Keywords="!(loc.Keywords)" 
      Comments="!(loc.Comments)"
      Languages="!(loc.Language)"
      />

    <!-- Downgrade Error Message -->
   <MajorUpgrade
      DowngradeErrorMessage="!(loc.DowngradeErrorMessage)" /> 
        <MediaTemplate 
      EmbedCab ="yes"
      />
    
    <!--Define Main app icon-->
    <!--<Icon Id="icon.ico" SourceFile="$(var.ConsoleApp1.ProjectDir)\app.ico" />-->
    
    <!--use the icon for the the installer Add/Remove programs -->
    <Property Id="APPPRODUCTICON">icon.ico</Property>
    <!--Hide the installer from Add/Remove programs -->
    <!--<Property Id='ARPSYstemCOMPONENT'>1</Property>-->
    <!-- Create a basic UI for the installer -->
    <UIRef Id='WixUI_Minimal'/>
    <!-- Change the installer UI background  Images And license file. -->
    <WixVariable Id='WixUILicenseRtf' Value='$(var.ProjectDir)\Assets\License.rtf'/>
    <WixVariable Id='WixUIDialogBmp' Value='$(var.ProjectDir)\Assets\Background.bmp'/>
    <WixVariable Id='WixUIBannerBmp' Value='$(var.ProjectDir)\Assets\Banner.bmp'/>
    <!-- Define components,shortcuts... etc for the installer-->
        <Feature Id="ProductFeature" Title="ConsoleApp" Level="1">
            <ComponentGroupRef Id="ProductComponents" />
        </Feature>
    <Binary Id="myAction"

        SourceFile="..\MyCustomAction\bin\Debug\MyCustomAction.CA.dll" />

    <CustomAction Id="myActionId"

                      BinaryKey="myAction"

                      DllEntry="MySimpleAction"

                      Execute="immediate"

                      Return="check" />

    <InstallExecuteSequence>
      <Custom Action="myActionId" After="InstallInitialize" />
    </InstallExecuteSequence>
    </Product>

</Wix>

但是当我运行安装程序时,它给出了错误。 “此Windows Installer软件包存在问题。无法完成安装所需的DLL。请与支持人员或产品供应商联系。

也不会调用自定义操作。我在bin文件夹中注意到的另一件事是,我有MyCustomAction.dll,但MyCustomAction.CA.dll不存在。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)