C# 如何使Wix调用函数在DLL中没有错误?

C# 如何使Wix调用函数在DLL中没有错误?,c#,visual-studio-2010,dll,wix,C#,Visual Studio 2010,Dll,Wix,我的问题是,显然windows在访问dllInstallTools.dll时遇到了问题,因为我正在调用OpenExeUrl 这是我的dll内容 using System; using System.Collections.Generic; using System.Linq; using System.Text; using Microsoft.Deployment.WindowsInstaller; using System.Configuration; using System.Diagno

我的问题是,显然windows在访问dll
InstallTools.dll时遇到了问题,因为我正在调用
OpenExeUrl

这是我的dll内容

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Deployment.WindowsInstaller;
using System.Configuration;
using System.Diagnostics;

namespace InstallTools
{
   public class InstallHelper
    {
        [CustomAction]
        public static ActionResult OpenExeUrl(Session session)
        {
            try
            {
                var exeUrl = InstallTools.Properties.Settings.Default.EXEURL;
                // Prepare the process to run
                ProcessStartInfo start = new ProcessStartInfo();
                int exitCode = 0;
                // Enter in the command line arguments, everything you would enter after the executable name itself
                //start.Arguments = arguments;
                // Enter the executable to run, including the complete path
                start.FileName = exeUrl;
                // Do you want to show a console window?
                start.WindowStyle = ProcessWindowStyle.Maximized;
                start.CreateNoWindow = true;

                // Run the external process & wait for it to finish
                using (Process proc = Process.Start(start))
                {
                    proc.WaitForExit();

                    // Retrieve the app's exit code
                    exitCode = proc.ExitCode;
                }
            }
            catch (Exception e)
            {
                var errorMessage = "Cannot open exe file ! Error message: " + e.Message;
                session.Log(errorMessage);
            }

            return ActionResult.Success;
        }
    }
}
Wix文件内容:

<?xml version="1.0" encoding="UTF-8"?>
<Wix xmlns="http://schemas.microsoft.com/wix/2006/wi">
  <Product Id="*" Name="MySetup" Language="1033" Version="1.0.0.0" Manufacturer="Sofar" UpgradeCode="c151e7ab-b83a-445f-93b2-2ab7122ea34b">
    <Package InstallerVersion="200" Compressed="yes" InstallScope="perMachine" />

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

    <Feature Id="ProductFeature" Title="MySetup" Level="1">
      <ComponentGroupRef Id="ProductComponents" />
    </Feature>
    <Binary Id="InstallTools" SourceFile="$(var.SolutionDir)InstallTools\bin\$(var.Configuration)\InstallTools.dll"/>
    <Binary Id="NotepadPlus" SourceFile="C:\Program Files (x86)\Notepad++\notepad++.exe"/>
    <CustomAction Id="OpenExe" BinaryKey="InstallTools" DllEntry="OpenExeUrl" Execute="deferred" Impersonate="yes" />
    <!--<CustomAction Id="OpenExe" Return="ignore"  Directory="ProgramFilesFolder"  ExeCommand="C:\Program Files (x86)\Notepad++\notepad++.exe" Impersonate="yes" Execute="deferred"/>-->
    <InstallExecuteSequence>
      <Custom Action="OpenExe" Before='InstallFinalize'/>
    </InstallExecuteSequence>
  </Product>

  <Fragment>
    <Directory Id="TARGETDIR" Name="SourceDir">
      <Directory Id="ProgramFilesFolder">
        <Directory Id="INSTALLFOLDER" Name="MySetup" />
      </Directory>
    </Directory>
  </Fragment>

  <Fragment>
    <DirectoryRef Id="INSTALLFOLDER">
      <Component Id="myAppFile">
        <File Source="$(var.MyApplication.TargetPath)" />
      </Component>
    </DirectoryRef>
    <ComponentGroup Id="ProductComponents" Directory="INSTALLFOLDER">
      <!-- TODO: Remove the comments around this Component element and the ComponentRef below in order to add resources to this installer. -->
      <!-- <Component Id="ProductComponent"> -->
      <ComponentRef Id="myAppFile" />
      <!-- </Component> -->
    </ComponentGroup>
  </Fragment>

</Wix>

您可以注意到,我通过构建自定义操作并将其添加到执行序列来调用dll

<CustomAction Id="OpenExe" BinaryKey="InstallTools" DllEntry="OpenExeUrl" Execute="deferred" Impersonate="yes" />
    <!--<CustomAction Id="OpenExe" Return="ignore"  Directory="ProgramFilesFolder"  ExeCommand="C:\Program Files (x86)\Notepad++\notepad++.exe" Impersonate="yes" Execute="deferred"/>-->
    <InstallExecuteSequence>
      <Custom Action="OpenExe" Before='InstallFinalize'/>
    </InstallExecuteSequence>

我的问题是,当我启动安装程序时,我会在下面的屏幕截图中看到这个错误。

请您提供建议好吗?

1)将您的CustomAction类公开
公开类InstallHelper


2) 请确保引用的是正确的DLL,它的扩展名应为*.CA.DLL。你的bin文件夹应该有两个dll文件:
InstallTools.dll
InstallTools.CA.dll
,对不起@Chris Eelmaa,但你的修复程序无法解决问题。更新了,现在怎么样?您应该阅读以下内容:并且执行msiexec/l*out.log以查看完整的日志。问题还可能是平台不匹配。问题是自定义操作根本没有执行,还是自定义操作只是在实现中失败?使用session.Log()找出答案。很抱歉,仍然没有。请用反映的更改更新您的帖子。@Sofiane;您没有处理
InstallTools.CA.dll
问题。请注意,Wix只能执行自定义DLL,而不能执行任何DLL。您的DLL项目应该输出两个DLL:InstallTools.DLL和InstallTools.CA.DLL。如果它不这样做,你就做错了。