Visual Studio 2008 安装程序项目 - 自定义操作未触发 [英] Visual Studio 2008 Installer Project - Custom Actions not firing

查看:32
本文介绍了Visual Studio 2008 安装程序项目 - 自定义操作未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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

  1. 我创建了安装程序项目
  2. 将 exe 添加到应用程序文件夹
  3. 转到自定义操作并将 exe 添加到提交步骤
  4. InstallerClass 设置为 true
  5. 运行安装程序,没有得到我希望的结果.所以我添加了一行写入 Windows 日志.再次运行安装程序后查看 Windows 日志,看起来它没有运行.在 exe 代码中添加了 debug.break 卸载/重新安装了我的安装程序,但什么也没发生.我终于坐下来观看进程并确认 exe 永远不会被执行.

有什么想法吗?

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

<小时>

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

<前>导入 System.ComponentModel导入 System.Configuration.Install_公共类应用程序安装程序继承安装程序公共重载覆盖子提交(ByVal savedState As IDictionary)' 在提交时做一些工作The_Sub_I_Want_To_Run()结束子公共重载覆盖子安装(ByVal stateSaver As IDictionary)' 做一些安装工作结束子公共重载覆盖子卸载(ByVal savedState As IDictionary)' 做一些卸载工作结束子结束类

<小时>

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

<代码>

<前>_公共类应用程序安装程序继承安装程序公共重载覆盖子提交(ByVal savedState As IDictionary)' 在提交时做一些工作The_Sub_I_Have_my_codein()MyBase.Commit(savedState)结束子公共重载覆盖子安装(ByVal stateSaver As IDictionary)' 做一些安装工作结束子公共重载覆盖子卸载(ByVal savedState As IDictionary)' 做一些卸载工作结束子结束类

<小时>

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

解决方案

您添加到 Commit 步骤的 exe 或库应包含派生自 安装程序 并标有 RunInstaller 属性如下:

[RunInstaller(true)]公共类 ApplicationInstaller :安装程序{公共覆盖无效提交(IDictionary savedState){//在提交上做一些工作}公共覆盖无效安装(IDictionary stateSaver){//做一些安装工作}公共覆盖无效卸载(IDictionary savedState){//做一些卸载工作}}

希望这会有所帮助.

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.

  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.

Any thoughts?

Targeted Systems: Windows XP, Vista Visual Studio Version: 2008 Sp1 Language: VB.NET Targeted Framework: 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:


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:

  _
    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.

解决方案

The exe or library you are adding to the Commit step should contain a class deriving from Installer and marked with the RunInstaller attribute as follows:

[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.

这篇关于Visual Studio 2008 安装程序项目 - 自定义操作未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆