windows Visual Studio 2008 安装程序项目 - 自定义操作未触发

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/321867/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 11:39:39  来源:igfitidea点击:

Visual Studio 2008 Installer Project - Custom Actions not firing

windowsvisual-studiovisual-studio-2008windows-installer

提问by Cj Anderson

I can't seem to get a custom action working. I might be doing this wrong. Here's what I'm trying to do:

我似乎无法使自定义操作起作用。我可能做错了。这是我想要做的:

I'd like to run a custom action in my application install (Visual Studio Installer project) that runs an executable. The executable simply does some system.io filecopy tasks, and I've confirmed that the executable when ran by itself works perfectly.

我想在运行可执行文件的应用程序安装(Visual Studio 安装程序项目)中运行自定义操作。可执行文件只是执行一些 system.io 文件复制任务,我已经确认该可执行文件在单独运行时可以完美运行。

  1. I created the installer project
  2. added the exe to the application folder
  3. went to custom actions and added the exe to the Commit step
  4. InstallerClass is set to true
  5. Ran the installer, didn't get the result I was hoping for. So I added a line to write to the windows log. Looked in the Windows log after running the installer again and it looked like it didn't run. Added a debug.break to the exe code Unisntalled/reinstalled my installer and nothing happened. I finally sat and watched the processes and confirmed the exe never gets executed.
  1. 我创建了安装程序项目
  2. 将exe添加到应用程序文件夹
  3. 转到自定义操作并将 exe 添加到提交步骤
  4. InstallerClass 设置为 true
  5. 运行安装程序,没有得到我希望的结果。所以我添加了一行写入 Windows 日志。再次运行安装程序后查看 Windows 日志,看起来它没有运行。在 exe 代码中添加了 debug.break 卸载/重新安装了我的安装程序,但什么也没发生。我终于坐下来观看了进程并确认 exe 永远不会被执行。

Any thoughts?

有什么想法吗?

Targeted Systems: Windows XP, Vista Visual Studio Version: 2008 Sp1 Language: VB.NET Targeted Framework: 2.0

目标系统:Windows XP、Vista Visual Studio 版本:2008 Sp1 语言:VB.NET 目标框架:2.0



Excellent. I think I'm getting closer thanks to the code you posted. I converted it to VB and i'm getting this error: Cannot Find myexename.savedstate. I assume I'm supposed to pass something to the subs you posted but I don't know what. (by the way this is a console application) I added a reference to the System.Configuration.Install.dll and here is my code:

优秀。由于您发布的代码,我想我越来越近了。我将其转换为 VB,但出现此错误:无法找到 myexename.savedstate。我想我应该向你发布的订阅者传递一些东西,但我不知道是什么。(顺便说一下,这是一个控制台应用程序)我添加了对 System.Configuration.Install.dll 的引用,这是我的代码:

Imports System.ComponentModel
Imports System.Configuration.Install

 _
    Public Class ApplicationInstaller
        Inherits Installer
        Public Overloads Overrides Sub Commit(ByVal savedState As IDictionary)
            ' Do some work on commit
            The_Sub_I_Want_To_Run()
        End Sub
        Public Overloads Overrides Sub Install(ByVal stateSaver As IDictionary)
            ' Do some work on install
        End Sub
        Public Overloads Overrides Sub Uninstall(ByVal savedState As IDictionary)
            ' Do some work on uninstall
        End Sub
    End Class


I did not call that. I've never used the Installer class before. I might be doing something very rookie here. Per your instructions, I've added the code that I have pasted below in the exe I want to run during my install. I added the exe to my application folder, then added it to the Commit custom action. Now here is the code I now have in the source of my exe that I'm trying to run:

我没有这么叫。我以前从未使用过 Installer 类。我可能会在这里做一些非常菜鸟的事情。根据您的指示,我已将粘贴在下面的代码添加到我想在安装过程中运行的 exe 中。我将 exe 添加到我的应用程序文件夹,然后将其添加到 Commit 自定义操作。现在这是我现在尝试运行的 exe 源代码中的代码:

  _
    Public Class ApplicationInstaller
        Inherits Installer
        Public Overloads Overrides Sub Commit(ByVal savedState As IDictionary)
            ' Do some work on commit
            The_Sub_I_Have_my_codein()
            MyBase.Commit(savedState)
        End Sub
        Public Overloads Overrides Sub Install(ByVal stateSaver As IDictionary)
            ' Do some work on install

        End Sub
        Public Overloads Overrides Sub Uninstall(ByVal savedState As IDictionary)
            ' Do some work on uninstall
        End Sub
    End Class



Hmmm... In the exe's Project Properties I clicked "Sign the assembly" and the error has gone away. However, looks like the exe doesn't run the code I want it to.

嗯...在 exe 的项目属性中,我单击了“对程序集进行签名”,错误就消失了。但是,看起来 exe 没有运行我想要的代码。

回答by Darin Dimitrov

The exe or library you are adding to the Commit step should contain a class deriving from Installerand marked with the RunInstallerattribute as follows:

您添加到 Commit 步骤的 exe 或库应包含一个派生自Installer的类,并用RunInstaller属性标记如下:

[RunInstaller(true)]
public class ApplicationInstaller : Installer
{
    public override void Commit(IDictionary savedState) {
      // Do some work on commit
    }
    public override void Install(IDictionary stateSaver) {
      // Do some work on install
    }
    public override void Uninstall(IDictionary savedState) {
      // Do some work on uninstall
    }
}

Hope this helps.

希望这可以帮助。

回答by Darin Dimitrov

Are you calling the base method?

你在调用基本方法吗?

public override void Commit(IDictionary savedState) {
    // Do some work on commit
    base.Commit(savedState);
}

回答by Andrey Neverov

Set

InstallerClass
属性为“假”。