Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/xml/13.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 如何将自定义操作添加到wix安装项目_C#_Xml_Wix_Action_Wix3.6 - Fatal编程技术网

C# 如何将自定义操作添加到wix安装项目

C# 如何将自定义操作添加到wix安装项目,c#,xml,wix,action,wix3.6,C#,Xml,Wix,Action,Wix3.6,我的解决方案中有两个项目: 1) 。自定义操作类(CustomAction) 2) 。Wix安装项目(TestSetup) CustomAction项目中有CustomAction.cs: using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Text; using Microsoft.Deployment.WindowsInstaller; namesp

我的解决方案中有两个项目:

1) 。自定义操作类(CustomAction)

2) 。Wix安装项目(TestSetup)

CustomAction项目中有CustomAction.cs:

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;

namespace CustomAction
{
    public class CustomActions
    {
        [CustomAction]
        public static ActionResult CustomAction1(Session session)
        {
            File.Create(@"c:\installed.txt");

            return ActionResult.Success;
        }
    }
}
Product.wxs:

<?xml version="1.0" encoding="UTF-8"?>

<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="TestSetup" Language="1033" Version="1.0.0.0" Manufacturer="SB2"
           UpgradeCode="39d922d3-a3f5-4207-b905-124615dda25d">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

    <Feature Id="ProductFeature" Title="TestSetup" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
    <InstallExecuteSequence>
      <Custom Action="CustomAction" Before="InstallFinalize" />
    </InstallExecuteSequence>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="TestSetup" />
      </Directory>
    </Directory>
  </Fragment>
  <Fragment>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <Component Id="result.rtf">
        <File Id="result.rtf" Source="result.rtf" KeyPath="yes" Checksum="yes" />
      </Component>
    </ComponentGroup>
  </Fragment>

<Fragment>
    <CustomAction Id='CustomAction' BinaryKey='CustomAction.CA' DllEntry='CustomAction' />
    <Binary Id='CustomAction.CA' SourceFile='..\CustomAction\bin\Debug\CustomAction.CA.dll' />
</Fragment>  
</Wix>

安装项目buils没有问题,但当我尝试运行它时,会收到一条错误消息: “此Windows Installer程序包有问题。无法运行完成此安装所需的DLL。请与技术支持人员或程序包供应商联系”

我认为这是因为不正确的二进制源文件值。
你能告诉我怎么修吗

问题在于您的CustomAction方法名称“CustomAction1”与您提到的“DLLEntry”值(DLLEntry='CustomAction')不匹配。您缺少“1”:


你应该这样写:-

<CustomAction Id='CustomAction' BinaryKey='CustomAction.CA' DllEntry='CustomAction1' />

其中CustomAction1是您的CustomAction名称

<CustomAction Id='CustomAction' BinaryKey='CustomAction.CA' DllEntry='CustomAction1' />