且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

VS2015 Visual Studio Insaller =>安装项目添加自定义操作

更新时间:2022-06-02 00:50:11

在VS2015上,您必须添加新项目(类库).将一个类添加到此项目,并从 System.Configuration.Install.Installer 继承.例如:

On VS2015, you have to add new project (class library). Add a Class to this project and inherits from System.Configuration.Install.Installer. For example:

using System.Collections;
using System.ComponentModel;
using System.Configuration.Install;
using System.Windows.Forms;`

namespace InstallerAction
{
    [RunInstaller(true)]
    public partial class InstallerPathAction : Installer
    {
        //Here override methods that you need for example
        protected override void OnBeforeInstall(IDictionary savedState)
        {
            base.OnBeforeInstall(savedState);
            //Your code and here abort the installation
            throw new InstallException("No master software");
        }
    }
}

然后,在您的安装程序项目中,添加自定义操作(选择安装程序项目>右键单击>视图>自定义操作>添加自定义操作),在应用程序文件夹中查找(双击应用程序文件夹)添加输出(选择具有以下内容的类库)安装程序类)的主要输出,然后单击确定.

Then, in your installer project, add custom action (Select Installer Project > rigth click > View > Custom Actions > Add Custom Action), Look in Application Folder (double click on Application Folder) Add Output (Select class library that has Installer class) Primary output and click OK.

您可以使用MessageBox进入安装程序类进行调试.

You can use MessageBox into installer class to debug.