Build/Test Issues

.NET Core test project does not pick up settings from app.config or appsettings.json

Started by samholder on 3,177 views

I'm migrating a project that was on .net framework to .net core 3.1.

I'm used to behaviour where if a test project has settings in the App.config, those settings get 'transferred' to the app.config of the NCrunch test execution application so that they are available if the tests do a ConfigurationManager.Appsettings["blah"] or similar. This behaviour seems to have changed now, as the tests always get an empty result if they read the config when running with NCrunch. I've tried creating an appsettings.json file but i don't see this copied anywhere in the NCrunch test execution directory.

Is there something I need to be doing differently now?
Hi, thanks for posting.

I'm personally unaware of anything particularly special that needs to be done to get settings working under NCrunch with .NET Core ... Although, I'm guilty of not being overly familiar with the settings model under .NET Core, and no one has asked me this question before. My guess is that there's something simple we're missing.

The first thing I'd recommend checking is whether you're able to build something that can use these settings outside of NCrunch. By taking NCrunch out of the picture, you can establish a clear baseline for that which you know NCrunch should be able to handle (you may have already done this).

The next thing I would check is whether the appsettings.json file is included in your project file or under NCrunch's 'Additional files to include' so that it gets copied to the workspace. I would presume that if the file needed to be in the build output directory, there should then be build steps that would copy it in there automatically.

I've been able to load up the appsettings.json during the tests by doing it manually, which is sufficient for me for now.

Post a reply

Log in to reply.