I'm writing a console application in C# in Visual Studio Community 2019 for Mac, and I added an App.config
file, I can't seem to access any of the values. How do I do this correctly? This may be related to the target framework being .Net core?
- I added the
System.Configuration.ConfigurationManager
NuGet package. - I added the App config file according to here
The contents of the app config are very simple:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<appSettings>
<add key="key" value="value" />
</appSettings>
</configuration>
The program definition is also very simple:
class Program {
static void Main(string[] args) {
Console.WriteLine("Config");
Console.WriteLine(ConfigurationManager.AppSettings["key"]);
foreach (var str in ConfigurationManager.AppSettings) {
Console.WriteLine(str);
}
foreach (var str in ConfigurationManager.ConnectionStrings) {
Console.WriteLine(str);
}
Console.WriteLine("End Config");
}
}
When I run the project from the play button, I expect to see value
twice in the output at least. Instead I get:
Config
data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|aspnetdb.mdf;User Instance=true
End Config
Press any key to continue...
In the bin/debug
folder there's only a ProjectName.dll
and no ProjectName.config
. What exactly could the problem be? Might it be related to this?