Search code examples
c#asp.netvisual-studio-2022desktop-applicationwindows-application-packaging

How to add config file in window installer


I have a window application in vs 2022 and also setup the installer (.msi) with application. It is working fine till now but as per new requirement i need to add config file and add all credential over there. I added there and now my application is correctly reading values from app.config but problem is when i create Installer (.msi) after install that on another machine then application is not reading value from app.config file. I don't want to use any third party tool. Please help on this


Solution

  • App.config:

    <?xml version="1.0" encoding="utf-8" ?>
    <configuration>
        <startup> 
            <supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.7.2" />
        </startup>
        <appSettings>
            <add key="MySetting" value="HelloWorld" />
        </appSettings>
    </configuration>
    

    Windows App: read config sample

    //using System.Configuration;
        string mySettingValue = ConfigurationManager.AppSettings["MySetting"];
        MessageBox.Show("MySetting value: " + mySettingValue);
    

    Right click installer project -> View -> File system

    enter image description here

    Right click Application Folder -> Add -> Project output

    enter image description here

    Select the Windows app project - > Primary output

    enter image description here