How to read values from config.json in Console Application

后端 未结 4 2218
南旧
南旧 2021-02-15 08:54

I just installed ASP.NET 5 and created a Console Application in Visual Studio. I\'ve added a file, config.json, to the root folder of the project.

It looks like this:

4条回答
  •  别跟我提以往
    2021-02-15 09:42

    The way you've worded your question, your config.json file is at the root of the project, but you're looking in the executable directory at runtime. Assuming you're doing this from Visual Studio, and assuming you're not copying the config file in at build time, Environment.CurrentDirectory is probably bin\Debug, and the file is not there.

    You can set the properties of config.json to Copy always from Solution Explorer, to ensure the file gets there.

提交回复
热议问题