Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

App.config: appSettings "file" attribute is not reading from the Local.config

Tags:

c#

app-config

I have a test project, with an App.config that sets up default values for some settings. I want to override these settings at the local level so each developer can, for instance, use their own credentials.

In my App.config I have the following:

<appSettings file="Local.config">
    <add key="Username" value="USERNAME"/>
    <add key="Password" value="PASSWORD"/>
</appSettings>

in the Local.config (in the same directory) I have the following:

<appSettings>
    <add key="Username" value="wayne"/>
    <add key="Password" value="secret"/>
</appSettings>

When I run my test I expect that getting the value of Username would return "wayne" from the Local.config; instead, it's "USERNAME" from the App.config - it seems as though it's not actually detecting that I want to override settings in another file.

What am I doing wrong?

like image 712
Wayne Molina Avatar asked Jun 14 '12 17:06

Wayne Molina


People also ask

How read app config file in C# Windows application?

Add the App. config file to your project. After creating a . NET Framework project, right-click on your project in Solution Explorer and choose Add > New Item. Choose the Application Configuration File item and then select Add.


1 Answers

I hate to ask, but are you sure the Local.config is being copied to the output directory?

like image 62
xelco52 Avatar answered Oct 05 '22 22:10

xelco52