1

I've created a windows form application ( called MyWinformsApp) with a personalized data per installation located in the App.config file. I need to build a generic installation file: so the personalized parameter must be included in the setup project. Therefore, I've build a setup project (called SetupProject which is linked to MyWinformsApp) using visual studio and I've added a Textbox field as an input for my personalized field. My question is : How can get the value of the textbox from the SetupProject and use it to update the App.config (of MyWinformsApp ). Thanks in advance.

  • You may find these posts useful: [Visual Studio Setup Project - Remove files created at runtime when uninstall](https://stackoverflow.com/q/46786297/3110834) or [Get user input during installation using setup project and use it in installer](https://stackoverflow.com/q/49783628/3110834) or [Get access to AppSettings from custom Installer during uninstall (BeforeUninstall)](https://stackoverflow.com/q/57316014/3110834) – Reza Aghaei Nov 15 '19 at 07:31

2 Answers2

0

The only way I know you can do this is to add an Installer class to your project so you could intercept install-related events like Install/Commit/Rollback/etc.

On Install event, for example, you'd have something like that:

public override void Install(IDictionary stateSaver)
{
    base.Install(stateSaver);
    string value = Context.Parameters["paramKey"];

    // Update App.config with the value
}

Basically you need to locate the App.config file (if it's placed in the installer files or as a resource file you should be able to get it) and update it in place.

I'm afraid there is no easier way of doing it mostly because the entire setup framework is no so flexible.

Cosmin Ioniță
  • 3,598
  • 4
  • 23
  • 48
0

In fact the custom install class should be added under the main project. Then we reference the class in the setup project. Just we need to add the class like this: Right click on the setup project-->View --> Custom Actions --> Select our project Output.