1.Console控制台程序没有问题
2.单元测试不可以,读取到的值是NULL
MSTest is running as testhost.dll, which means that ConfigurationManager is reading settings from testhost.dll.config when executing under .NET core. <br>It will look for testhost.dll.config where the testhost.dll is located as the accepted answer states. <br>What is not mentioned is that it will also look for testhost.dll.config in the location where you have your test dlls.
1. 在单元测试工程中将app.config文件改为:testhost.dll.config
2. 修改单元测试工程文件,配置编译后事件,动态copy生成testhost.dll.config