简体   繁体   English

OnAfterInstall活动在哪里?

[英]Where does OnAfterInstall event go?

I've had serious problems on how to solve this: I don't know where the OnAfterInstall event goes. 我在如何解决这个问题上遇到了严重的问题:我不知道OnAfterInstall事件的去向。

Let me explain myself. 让我解释一下自己。 I created a C# project which compiles perfectly and built in Release mode. 我创建了一个C#项目,它完美地编译并在Release模式下构建。 After that, I've created a Setup Project using the wizard. 之后,我使用向导创建了一个Setup Project。 I have added an extra dialog, which lets the user choose between two languages. 我添加了一个额外的对话框,允许用户在两​​种语言之间进行选择。 Now, my problem is that I want to store that language into the registry (or app.config file, the easier the better), and I've read that you need to detect it within the OnAfterInstall method in an inherited class of Installer. 现在,我的问题是我想将该语言存储到注册表(或app.config文件中,越简单越好),并且我已经读过你需要在继承的Installer类中的OnAfterInstall方法中检测它。

Now, where should I put that class? 现在,我应该把那个班级放在哪里? Logic tells me it goes in the C# project, but it complains that neither Context nor Installer class exist. Logic告诉我它在C#项目中,但它抱怨Context和Installer类都不存在。 When I add this class to the Setup Project, it doesn't complain, but it doesn't work after that. 当我将此类添加到安装项目时,它不会抱怨,但在此之后它不起作用。 Here's the class. 这是班级。

using System;
using System.Configuration.Install;

public class Install : Installer
{
    public Install()
    {
    }

    protected override void OnAfterInstall(IDictionary savedState)
    {
        string lang = Context.Parameters["lang"];
        RegistryKey key = Registry.LocalMachine;
        using (key = key.CreateSubKey(@"SOFTWARE\MyCompany\MyApp"))
        {
            key.SetValue("lang", lang);
            key.Close();
        }
        base.OnAfterInstall(savedState);
    }
}

PS: I'm already passing lang as CustomActionData using /lang=[LANG] (where LANG is the radio value) PS:我已经使用/ lang = [LANG]传递lang作为CustomActionData(其中LANG是无线电值)

First, you should add the RunInstallerAttribute to you class. 首先,您应该将RunInstallerAttribute添加到您的类。

[RunInstaller(true)]
public class Install : Installer
...

Next, put the installer in a separate project (class library), eg MyCustomInstaller. 接下来,将安装程序放在单独的项目(类库)中,例如MyCustomInstaller。

Finally, add the primary output of this project to a custom action in the custom actions editor of the setup project. 最后,将此项目的主要输出添加到安装项目的自定义操作编辑器中的自定义操作。

在此输入图像描述

It's up to you in which custom action you want to use. 您可以使用自定义操作

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM