What is App.config in C#.NET? How to use it?

前端 未结 6 1976
情深已故
情深已故 2020-11-22 15:00

I have done a project in C#.NET where my database file is an Excel workbook. Since the location of the connection string is hard coded in my coding, there is no problem for

6条回答
  •  不要未来只要你来
    2020-11-22 15:44

    Just to add something I was missing from all the answers - even if it seems to be silly and obvious as soon as you know:

    The file has to be named "App.config" or "app.config" and can be located in your project at the same level as e.g. Program.cs.

    I do not know if other locations are possible, other names (like application.conf, as suggested in the ODP.net documentation) did not work for me.

    PS. I started with Visual Studio Code and created a new project with "dotnet new". No configuration file is created in this case, I am sure there are other cases. PPS. You may need to add a nuget package to be able to read the config file, in case of .NET CORE it would be "dotnet add package System.Configuration.ConfigurationManager --version 4.5.0"

提交回复
热议问题