4

Scenario: I installed Visual Studio on Mac and created a console application. Using Nuget I installed a library that needs some info from appSettings.

I do not have any app.config file or where I can add XML for appSettings

Question: Do I need to create it myself or how does that work?

Please excuse my noob question but I have no idea how to get around this.

enter image description here

mrogal.ski
  • 5,828
  • 1
  • 21
  • 30
Ghisoi Ioan
  • 71
  • 1
  • 6
  • 2
    Dotnet core uses appsettings.json files for configuration. You should be able to add one to your project, but a quick google search will show you plenty of examples. – David Watts Sep 11 '17 at 13:30

1 Answers1

3

There is an app.config file template you can use that is provided by Visual Studio for Mac.

From the File menu select New File. Then select Misc - Application Config File in the new file dialog.

Then add your appSettings to that file.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <appSettings>
        <add key="Application Name" value="MyApplication" />
    </appSettings>
</configuration>

To avoid the warning about using System.Configuration.AppSettings, since this is deprecated, you will need to add a reference to System.Configuration by right clicking the References in the Solution window, selecting Edit References. Then search for System.Configuration in that dialog. Tick the reference and click OK. Then you can use System.Configuration.ConfigurationManager.AppSettings.

string setting = System.Configuration.ConfigurationManager.AppSettings["Application Name"];
Matt Ward
  • 47,057
  • 5
  • 93
  • 94