C#安装项目“自定义操作”将安装目录保存到自定义设置文件 [英] C# Setup Project Custom Action to save the installation directory to custom setting file

查看:574
本文介绍了C#安装项目“自定义操作”将安装目录保存到自定义设置文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用Windows Installer作为安装方法来制作应用程序。安装成功后,我要获取在安装程序中配置的主要输出所在的路径。在我的情况下,主要输出在文件夹 [ApplicationData(Installroot)] \Bin\ 中。

I am trying to make an application using windows installer as it's install method. When the installation succeeds I want to get the path where the primary output is located that I configured in the installer. In my case the primary output is in the folder [ApplicationData(Installroot)]\Bin\.

我的类库中还有一个名为App.Settings的自定义设置文件,它控制着几个设置,例如相对于安装位置的文件位置。

I also have a custom settings file called App.Settings in 1 my Class Library which controls several settings like file locations who are relative to the install location.

当安装成功后,应调用App.Settings并将安装文件夹保存到设置文件中。

So the idea is that when the installation succeeds it should call the App.Settings and save the install folder to the settings file.

我已经制作了一个Install类并将其放在类库中。我不确定是否应该在该项目中。
这是安装类的代码:

I already made an Install class and put it inside the Class Library. I am not sure if it is supposed to be in that project though. This is the code of the Install Class:

using System.Collections;
using System.ComponentModel;

namespace WaspbaneModels
{
    [RunInstaller(true)]
    public partial class Installer : System.Configuration.Install.Installer
    {
        public Installer()
        {
            InitializeComponent();
        }

        public override void Install(IDictionary stateSaver)
        {
            base.Install(stateSaver);
        }

        public override void Commit(IDictionary savedState)
        {
            base.Commit(savedState);

            SettingsControl.BaseURL = Context.Parameters["assemblypath"];
            SettingsControl.Save();
        }

        public override void Rollback(IDictionary savedState)
        {
            base.Rollback(savedState);
        }

        public override void Uninstall(IDictionary savedState)
        {
            base.Uninstall(savedState);
        }
    }
}

在此代码中,SettingsControl是类,它仅通过一些属性来处理设置。我使用了此类,以便Windows Forms项目也可以访问这些设置。

In this code SettingsControl is the class that takes care of the Settings simply with some properties. I used this class so that my Windows Forms project also can access these settings.

在自定义操作选项卡中,我还向所有内容添加了主输出。我也不确定这是否正确,因为我认为主要输出包含所有的.dll文件,包括类库。

In the Custom Actions tab I also added the Primary Output to everything. I am also not sure if this is correct because I think the Primary Output contains all .dll files including the Class Libraries.

我不太确定从哪里继续但请注意,因为未保存设置。我只是通过在应用程序启动时放置一个消息框来检查此情况,以提供设置的值。

I am not really sure where to continue from this point however because the Settings are not saved. I simply check this by putting up a messagebox at the startup of the application giving me the value of the setting.

任何对项目更多数据感兴趣的人都可以问。我只是不会立即发布所有内容。

Anyone interested in more data of the project just ask. I just won't post everything at once yet.

编辑:

经过更多测试之后,我设法找出未调用Installer类。我添加了一些将在调用该方法但无任何反应的情况下写到文件中的东西。

After some more testing I managed to find out that the Installer class isn't being called upon. I added something that would write out to a file when the method would've been called but nothing happened.

因此,我现在的问题是:如何添加自定义操作正确地安装程序项目?

Therefore my question now is: How do I add the Custom Action to the Setup project properly?

推荐答案

您可以将自定义操作类(.dll)添加到安装程序项目。您必须将 InstallerActions .dll添加到安装和提交操作。

You can add the custom action class (.dll) to the Setup project. You have to add the InstallerActions.dll to the Install and Commit actions.

要添加自定义操作


  1. 在解决方案资源管理器中选择 Setup Installer 项目。在
    的查看菜单上,指向编辑器,然后单击自定义操作。将显示
    自定义动作编辑器。

  2. 在自定义动作编辑器中,选择提交节点。在操作
    菜单上,单击添加自定义操作。

  3. 在项目中的选择项目对话框中,双击
    应用程序文件夹。从 InstallerActions
    项目中选择主要输出。 InstallerActions的主要输出显示在自定义动作编辑器中的
    Commit节点下。

  4. 在属性窗口中,确保InstallerClass属性
    设置为True(这是默认设置。)

  5. 在自定义操作编辑器中,选择安装节点,然后从 InstallerActions 中添加
    主要输出。 >就像您对
    Commit节点所做的一样。

  1. Select the Setup Installer project in Solution Explorer. On the View menu, point to Editor, and then click Custom Actions. The Custom Actions Editor is displayed.
  2. In the Custom Actions Editor, select the Commit node. On the Action menu, click Add Custom Action.
  3. In the Select Item in Project dialog box, double-click the Application Folder. Select Primary output from InstallerActions project. Primary output from InstallerActions appears under the Commit node in the Custom Actions Editor.
  4. In the Properties window, make sure that the InstallerClass property is set to True (this is the default).
  5. In the Custom Actions Editor, select the Install node and add Primary output from InstallerActions to this node as you did for the Commit node.

这篇关于C#安装项目“自定义操作”将安装目录保存到自定义设置文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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