Martin Brabec
Martin Brabec

Reputation: 3840

c# there is no relevant app.config after release

can somebody please tell me how to treat with app.config? It created itself when I created some values in app.Properties. I set the code file to "CopyAlways". But, when I compile application in debug or release mode, edit config manualy(with Notepad) and start application, it behaves like there are no changes in config file. I tried to change app.config, appname.exe.config and even appname.vschost.exe.config.

What is even more interesting for me is that I can build an app, then copy source files (appname.exe and dll files) without any config file to any new folder, and start an application. It connect to server, despite the fact, that there is no config, where is stored IP.

I found only questions about changing app.config during runtime by code. But this is not I want. I have config for data, that dont change a lot. And .settings for user settings (color of record in datagrid etc).

I tought, that config is read everytime app started. Do I realy have to create my own config file, which will be in the same folder as exe and will be read everytime app starts?

Only support I found on msdn is how to create app.config.

Upvotes: 3

Views: 4153

Answers (3)

Pinte Dani
Pinte Dani

Reputation: 2049

You should not change the properties of App.config to "Copy Always".

When you build your application, the compiler creates a YourAppName.exe.config file in your output directory, which contains exactly the same values as your App.config file.

If you later change the values from YourAppName.exe.config this will be visible when you start your app, without needing to rebuild.

Upvotes: 1

giammin
giammin

Reputation: 18958

you do not need to copy your app.config or set it as "CopyAlways".

When you build visual studio copy it automatically renaming it applicationName.exe.config

so if your applicaion is: MyApplication.exe you should find in the bin the file MyApplication.exe.config

You are confusing app.config with application settings which are stored in the file user.config inside UserProfile directory.

Application Settings Overview

Application Settings Architecture

They are meant to be used to store user preference as backgroundcolor, visualizzation preferences etc etc

Instead if you want a config value easily changeable you should use the appSettings node in app.config

    <appSettings>
    <add key="ServerIp" value="0.0.0.0"/>
</appSettings>

and access it from your code:

ConfigurationManager.AppSettings["ServerIp"]

ConfigurationManager.AppSettings

Upvotes: 0

Jehof
Jehof

Reputation: 35544

Settings of an application that are in UserScope are stored under Application.LocalUserAppDataPath (Normally this is C:\Documents and Settings\username\Local Settings\Application Data\ as base path + the following schema \CompanyName\ProductName\ProductVersion). So when you run your application a user.config is stored in this folder and is used for further starts of your application.

The app.config of your application only contains the default values if no user.config is found in the path above.

Open your explorer and check the path of Application.LocalUserAppDataPath if there is a .config file of your application. If so remove it or change the settings in this file.

Upvotes: 0

Related Questions