0

I need your opinion on this: Is it possible to use enterprise library logging dll in the setup project?

Here's what I did: I created a setup project which will call a windows form to install the database. When I installed the project, it did call the windows form. However, when I click on the "Install" button, it seems that there's a problem and I don't know where it is. Then another popup message is displayed which said that it cannot locate the logging configuration.

But the config file for the windows form is there which includes the configuration for the logging dll. I don't have any idea where to look into.

Please help me with this?

Below is the error message: enter image description here

UPDATE I observed that when I run the exe file as is, the enterprise library logging config works. But with the setup project, it does not look for it. Any help on this?

Below is the code for this:

[RunInstaller(true)]
public partial class IPWInstaller : Installer
{
    public IPWInstaller()
    {
        InitializeComponent();
    }

    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);
        string targetPath = Context.Parameters["TargetDir"];
        InstallDatabase db = new InstallDatabase(targetPath);

        DialogResult dbResult = db.ShowDialog();

        if (dbResult != DialogResult.OK)
        {
            throw new InstallException("Database is not installed.");
        }

        ConfigureFiles config = new ConfigureFiles(targetPath);
        DialogResult configResult = config.ShowDialog();

        if (configResult != DialogResult.OK)
        {
            throw new InstallException("Config files are not saved correctly.");
        }
    }
}

LATEST UPDATE:

I tried to set the value of a certain configuration to my messagebox. This is the result of it when I run the install project. enter image description here

Is there a way to call my app.config in the setup project

Musikero31
  • 3,115
  • 6
  • 39
  • 60
  • Is the app.config getting written to disk by the installer before you display the form? – Brendan Green Dec 09 '14 at 03:21
  • The app.exe.config gets written to the disk by the installer. Will edit the question to show you the installer class. Also, the installer class is inside the same project where the app.config is. – Musikero31 Dec 09 '14 at 03:37
  • @BrendanGreen: Please check my latest update. Is there any way for me to use the app.config? – Musikero31 Dec 09 '14 at 07:18

1 Answers1

1

There are at least a couple of things that can go wrong.

The app is not running as it would if you ran it as an interactive user. It is being called from an msiexec.exe process that knows nothing about your intended environment, such as working directory. None of the automatic things that happen because you run from an explorer shell will happen. Any paths you use need to be full and explicit. I think you may need to explicitly load your settings file.

Something else that can happen in a per machine install is that custom actions run with the system account so any code which assumes you have access to databases, user profile items like folders can fail.

Another problem is that Windows Forms often don't work well when called from a VS custom action. It's not something that works very well because that environment is not the STA threading model that is required for window messages etc.

In general it's better to run these config programs after the install the first time the app starts because then you are in a normal environment, debugging and testing is straightforward, and if the db gets lost the user could run the program again to recreate it instead of uninstalling and reinstalling the setup.

PhilDW
  • 20,260
  • 1
  • 18
  • 28
  • Ok... Here are two points which I got: (1) I'm thinking of using an XML to hold the configuration, and (2) I think I should use the AfterInstall event so that I can call the forms. Is this correct? – Musikero31 Dec 10 '14 at 01:25
  • Should I be using the AfterInstall event or not? Because I need to display the form to do the database setup – Musikero31 Dec 10 '14 at 02:24
  • All VS custom actions run after all the files have been installed, whether they're called Onstall, AfterInstall, whatever, so it makes no difference. An Install custom action will run after everything has been installed! – PhilDW Dec 10 '14 at 18:42