My unit test project has its own appsettings.json file.
In the same solution, I have an ASP.NET Core 3.1 WebAPI Project with an appsettings.json file.
I also have an ASP.NET Core 3.1 Razor project that has an appsettings.json file.
When I run my unit tests, the appsettings.json file from the WebAPI project is copied into the debug folder of my unit tests.
If I do a full rebuild, then the unit test project's appsettings.json file is copied into the debug folder. But then when I run a unit test (by pressing ctrl + R + T), the WebAPI project's appsettings.json file is again copied in.
I assumed that the appsettings.json file copied into the project's debug folder would correspond with the appsettings.json file in that project. (And it does for a full rebuild.)
How can I specify which appsettings.json file should be copied to the debug folder of a project's build?
I am not sure what shenanigans .net core is trying to do by swapping in a different appsetting.json file, but setting my unit test project's appsettings.json file to be an embedded resource made it copy it over.
https://stackoverflow.com/a/49778593/16241
I found this bug listed in the Microsoft Developer Community forum. The workaround specifically sited in this link appears to have worked on VS 2022, version 17.9.2.
https://developercommunity.visualstudio.com/t/appsettingsjson-not-being-picked-up-in/10584312#T-N10609558
It's not a fix, but at least it gets past the problem.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With