【问题标题】:How to make Wix call function inside a DLL without errors?如何使 DLL 中的 Wix 调用函数没有错误?
【发布时间】:2014-10-09 19:58:44
【问题描述】:

我的问题是显然 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>

我的问题是,当我启动安装程序时,出现以下屏幕截图中显示的此错误。

你能指点一下吗?

【问题讨论】:

    标签: c# visual-studio-2010 dll wix


    【解决方案1】:

    1) 将您的 CustomAction 类设为publicpublic class InstallHelper

    2) 确保您引用了正确的 DLL,它应该以 *.CA.dll 扩展名结尾。您的 bin 文件夹应该有两个 dll 文件:InstallTools.dllInstallTools.CA.dll

    【讨论】:

    • 很抱歉@Chris Eelmaa,但您的修复无法解决问题。
    • 更新了,现在呢?您应该阅读以下内容:blogs.msdn.com/b/jschaffe/archive/2012/10/23/… 并执行 msiexec /l* out.log 以查看完整日志。问题也可能是平台不匹配。问题自定义操作是否根本没有执行,或者自定义操作是否在实施中失败?使用 session.Log() 找出答案。
    • 很抱歉,但仍然没有。
    • 使用反映的更改更新您的帖子。
    • @Sofiane;你没有处理InstallTools.CA.dll 的问题。请注意,Wix 只能执行自定义 DLL,不能执行任何 dll。您的 DLL 项目应该输出两个 dll:InstallTools.dll 和 InstallTools.CA.dll。如果它不这样做,你就做错了。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 2012-12-28
    • 2015-03-31
    • 1970-01-01
    相关资源
    最近更新 更多