Reputation: 11
I'm trying to execute my SpecFlow tests through nunit3-console runner but I'm receiving the following error:
System.IO.FileNotFoundException : The configuration file 'appsettings.json' was not found and is not optional. The expected physical path was 'C:\Users\...\.nuget\packages\nunit.consolerunner\3.15.0\tools\agents\net6.0\appsettings.json'.
Obviously the runner tries to find the configuration file in the nunit3-console package directory instead of the active/current directory where the file has been copied. Is there any way to specify the correct file directory?
The command I used is the following (or see the image below):
[nunit3-console runner package path] [test .dll path] --trace=off
Maybe it's visible but the nunit3-console runner package I'm using is version 3.15.0 and the version of the framework is .net 6.
Here is the detailed error:
Upvotes: 0
Views: 930
Reputation: 11
Update:
The problem turned out to be the way the configuration was built.
Before:
Configuration = new ConfigurationBuilder()
.SetBasePath(AppDomain.CurrentDomain.BaseDirectory)
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
After:
Configuration = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json", optional: false, reloadOnChange: true)
.Build();
And the difference between those two looks like that:
AppDomain.CurrentDomain.BaseDirectory
"C:\\Users\\...\\source\\repos\\qa-automation\\...\\bin\\Debug\\net6.0\\"
Directory.GetCurrentDirectory()
"C:\\Users\\...\\source\\repos\\qa-automation\\...\\bin\\Debug\\net6.0"
Upvotes: 1