This is the code I have implemented to check whether the process is running or not.I have reerred .NET Core 3.1 loading config from appsettings.json for console application. but I get an error as the attached below.Even after importing the libraries.
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.Configuration.Json;
class Program
{
static void Main(string[] args)
{
IConfiguration configuration = new ConfigurationBuilder()
.AddJsonFile("appsettings.json", true, true)
.Build();
var processSection = configuration.GetSection(nameof(Process));
}
Iam not sure whether my code under main method is correct or not,what i wanted to do is, I want to read the names of the processes from appsettings file.
Can someone please let me know how can I do it.
Thankyou.
appsettings.json file is as below
{
"Process": {
"name": "notepad"
}
}
the .csproj file is,
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp2.2</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Configuration" Version="5.0.0" />
</ItemGroup>
</Project>