Home

Where is App.config in LinqPad 6?

Hi ~

I've downloaded the LinqPad 6 app. I noticed that it doesn't have the App.config tab as on LinqPad 5. How do I reference my app.config xml settings in LinqPad 6?

Comments

  • .NET Core has moved away from app.config to appsettings.json.

    To reference an appsettings.json file, press F4 and add a reference to it. (This works because any non-assembly files that you reference are automatically copied to the application base directory before the query executes.)

  • Can I create a custom appsettings.json file for each program and reference it? Like [appname].appsettings.json.

  • Also, how would I reference the appsettings.json or [appname].appsettings.json file if I'm using Log4Net? Here's my code:
    static readonly ILog Log = log4net.LogManager.GetLogger("LogFileAppender");
    void Main()
    {
    XmlConfigurator.Configure();
    Log.Info("Startup Application");
    }

  • The appsettings.json file is not usually prefixed with the application name. So you just need to reference a file called appsettings.json.

  • Once I have referenced the appsettings, how do I access it from C# program?

    Also if I change the appsettings.json file, do I have to re-reference it?

  • edited August 2020

    First, press Shift+Ctrl+P add a NuGet reference to the Microsoft.Extensions.Configuration.Json package.

    Then you can read the appsettings.json file as follows:

    var builder = new ConfigurationBuilder()
        .AddJsonFile ("appsettings.json");
    
    IConfiguration config = builder.Build();
    config.GetSection ("Logging").GetSection ("LogLevel").GetSection ("Default").Value.Dump();
    

    You won't need to do anything if the appsettings.json file changes - LINQPad will automatically detect this scenario.

    Also keep in mind that you don't necessarily need to use an appsettings.json file to store configuration data. You can use any format such as a text file, a json file or an XML file and read it as you please. For example, you could reference a file called config.xml and read it as follows this:

    string id = (string) XDocument.Load ("config.xml").Root.Element ("Test");
    id.Dump();
    
  • I tried referencing app.config but the configuration manager still could not find it. Is there a way to continue to use app.config? I have over a hundred pieces of code that in LINQPad that use the configuration manager to get their configuration info.

Sign In or Register to comment.