I have a class library created with dot net core 3.1. There are two files which I am using for logging and reading appsetting.json file. For this I am using two custom class files respectively for logging and reading appesttings.json file. Here is sample code for same.
1)Logging (File 1:CustomLogger.cs)
2)Reading appsetting.json (File 2: ConfigHelper.cs)
Now I am consuming my class library by adding project reference in another separate console application.
When I run my console application, I am getting an exception in GetCurrentSettings method where I am not able to reach to appsetting.json file. Instead it is trying to find that file in current console application of bin folder.
So How could I read appsetting.json values from base project.
CodePudding user response:
The error you are getting is because the appsettings SHOULD be copied to the bin folder as part of the build.
appsettings.X.json
should have a setting:
Copy to output directory: "Copy if newer"
CodePudding user response:
Right click on the appsettings.json
file and set the Copy to output directory value as Copy if never or Copy always