1

Why there is no app.config file in my c# console application by default. I have been watching many tutorials on entityframework, and in all of them, there is app.config by default. Why i dont have it in my console app? enter image description here I need that file so i can add configure string to it

Charles Mager
  • 25,735
  • 2
  • 35
  • 45
kims9
  • 45
  • 1
  • 4
  • 1
    Are you using .NET Core (or .NET 5 or 6) or are you using .NET Framework? – MindSwipe Apr 08 '22 at 06:41
  • 1
    just to be sure, is it a `.Net Framework` or a `.Net Core` project? you can check on project properties (right click your project > properties). the thing is `.Net Framework` uses `app.config` while the `.Net Core` uses `appsettings.json`. – Bagus Tesa Apr 08 '22 at 06:41
  • 1
    [How to: Add an application configuration file to a C# project](https://learn.microsoft.com/en-us/visualstudio/ide/how-to-add-app-config-file?view=vs-2022) – Jeroen van Langen Apr 08 '22 at 06:41
  • 2
    `app.config` isn't used in .NET Core onwards (without [some effort to add it back](https://stackoverflow.com/a/46482184/1320845)), and EF Core won't use it either. I suspect the tutorials you've been watching relate to .NET Framework and Entity Framework 6. – Charles Mager Apr 08 '22 at 06:41
  • 3
    .NET 5/6 are .NET *Core* 5 and 6. .NET Core no longer uses `app.config` files. You'll find an `appsettings.json` file instead. You're probably looking at an outdated tutorial. Instead of trying to add `app.config` for no benefit, find a better tutorial. The new config system is completely different, far easier to use and actually allows mixing multiple config sources, including env variables, files, databases, remote services. `appsettings.json` is just a common name for a JSON config file. You can easily add your own. – Panagiotis Kanavos Apr 08 '22 at 06:47
  • 1
    .net core: are you looking for appsettings.json ? This is not added by default to keep things simple as apps might not need it. You can add just like any other file in your application. – Santosh Karanam Apr 08 '22 at 06:47
  • 2
    If you really want to learn about the old Entity Framework, you need to create a .NET Framework Console application, not .NET/.NET Core console. The old EF is in maintenance mode though, all new features are added to Entity Framework Core. – Panagiotis Kanavos Apr 08 '22 at 06:49
  • 1
    FYI Entity Framework Core (EF Core), the Entity Framework "version" for .NET Core, is a ground up re-implementation of Entity Framework, and such is fundamentally different in some ways. I recommend you either look at tutorials that teach EF Core *or* (as a learning exercise) switch to using .NET Framework – MindSwipe Apr 08 '22 at 06:49
  • 2
    Thank you guys for your help. The thing is that i have been using .Net 5 and watched outdated tutorials. I will watch tutorials on EntityFrameworkCore now. – kims9 Apr 08 '22 at 06:54

1 Answers1

1

The newer .NET Cores (5 & 6) no longer use a app.config file.

You should use an appsettings.json file.

From the Microsoft docs:

All of the application's settings are contained in a file named appsettings.json. Any changes to the appsettings.json file will require restarting the "Microsoft IIS Administration" service to take effect.

The appsettings.json file is located at: %SystemDrive%\Program Files\IIS Administration<version>\Microsoft.IIS.Administration\config\appsettings.json

But not just for web apps, but any Console app also follows the same config methodology. The above link has examples to cover most cases.

Fandango68
  • 4,461
  • 4
  • 39
  • 74