Can't read app.config in C# .NET Core unit test project with ConfigurationManager

前端 未结 10 832
迷失自我
迷失自我 2020-12-15 15:13

I\'ve created a simple unit test project to read an app.config file. Target framework is Core 2.0. I also created a Core 2.0 console app, to sanity-check myself to make sure

10条回答
  •  -上瘾入骨i
    2020-12-15 15:53

    If you check the result of the call to ConfigurationManager.OpenExeConfiguration(ConfigurationUserLevel.None);

    It should tell you where the required configuration file should be while running unit tests for that assembly.

    I found that instead of having an app.config file, ConfigurationManager was looking for a testhost.dll.config file.

    This was for a project targeting netcoreapp2.1, with a reference to Microsoft.NET.Test.Sdk,NUnit 3.11 and Nunit3TestAdapter 3.12.0

提交回复
热议问题