I\'m trying place a DB connection string in an app config file for my C# console project in VS Community 2019 so I can access the string from a central location. I had to cr
It took all day looking through the forums for this one. I'm using .NET Core 3.0 in Visual Studio Community 2019. Basically, my ConfigurationManager was trying to access a config file from ~\bin\debug\netcoreapp3.0\DESCLogicFramework.dll.config. Where this file originated from I have no idea, but I assume it was just created automatically on building my app. Bottom line, I had to overwrite it.
On a side note: I found this out using:
var configfile = ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);
and then exploring the configfile object in the debugger, and finding a property called "Filepath".
The steps I took to correct it were:
Rename my app.config file to be 'assemblyname'.exe.config, for example mine ended up being "DESCLogicFramework.exe.config"
Place this config file in my root project directory.
Change the config file Build Action Property to "Application definition" and its "Copy to Output Directory" Property to "Copy if newer". Both these can be accessed by right clicking on your config file and selecting "Properties". It will bring up the Properties window.
Opening up the project's .csproj file, and adding the following lines of xml right before the closing ProjectTag, you tell the build to copy your .config file to the build location and give it the .dll.config extension.
var conn = ConfigurationManager.ConnectionStrings["DBconnection"];
Edit: I am still not seeing the Settings Editor in my Project Properties, but I was able to solve the issue I was having without it.