簡體   English   中英

如何向wix安裝項目添加自定義操作

[英]How to add custom action to wix setup project

我的解決方案中有2個項目:

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>

安裝項目建立沒有問題,但當我嘗試運行它時,我收到一條錯誤消息:“此Windows Installer程序包有問題。無法運行此安裝所需的DLL。請聯系您的支持人員或包裝供應商“

我認為這是因為二進制源文件值不正確。 你會說明如何解決它嗎?

問題是您的CustomAction方法名稱“CustomAction1”與您提到的“DLLEntry”值不匹配(DllEntry ='CustomAction')。 你錯過了“1”:)

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

你應該這樣寫: -

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

其中CustomAction1是您的CustomAction名稱..

暫無
暫無

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

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