VS2015 Visual Studio Insaller =>安装项目添加自定义操作 [英] VS2015 Visual Studio Insaller=>Setup Project add custom action

查看:62
本文介绍了VS2015 Visual Studio Insaller =>安装项目添加自定义操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想检查是否安装了主软件,如果没有安装主软件,则中止安装.检查我是否收到代码

i want to check if master software is installed or not, if master software not install then abort setup. for check that i get code

/// <summary>
/// To check software installed or not
/// </summary>
/// <param name="controlPanelDisplayName">Display name of software from control panel</param>
private static bool IsApplictionInstalled(string controlPanelDisplayName)
{
    string displayName;
    RegistryKey key;

    // search in: CurrentUser
    key = Registry.CurrentUser.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
    if (null != key)
    {
        foreach (string keyName in key.GetSubKeyNames())
        {
            RegistryKey subkey = key.OpenSubKey(keyName);
            displayName = subkey.GetValue("DisplayName") as string;
            if (controlPanelDisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
            {
                return true;
            }
        }
    }

    // search in: LocalMachine_32
    key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Microsoft\Windows\CurrentVersion\Uninstall");
    if (null != key)
    {
        foreach (string keyName in key.GetSubKeyNames())
        {
            RegistryKey subkey = key.OpenSubKey(keyName);
            displayName = subkey.GetValue("DisplayName") as string;
            if (controlPanelDisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
            {
                return true;
            }
        }
    }
    // search in: LocalMachine_64
    key = Registry.LocalMachine.OpenSubKey(@"SOFTWARE\Wow6432Node\Microsoft\Windows\CurrentVersion\Uninstall");
    if (null != key)
    {
        foreach (string keyName in key.GetSubKeyNames())
        {
            RegistryKey subkey = key.OpenSubKey(keyName);
            displayName = subkey.GetValue("DisplayName") as string;
            if (controlPanelDisplayName.Equals(displayName, StringComparison.OrdinalIgnoreCase) == true)
            {
                return true;
            }
        }
    }
    // NOT FOUND
    return false;
}

,但不知道该函数放在何处以及在何处调用.请帮助我.

but don't know where to put and where to call this function. please help me.

提前谢谢.

推荐答案

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

这篇关于VS2015 Visual Studio Insaller =&gt;安装项目添加自定义操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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