【问题标题】:Get custom configuration .cs file path in a class library project that is being referenced by a console applicationGet custom configuration .cs file path in a class library project that is being referenced by a console application
【发布时间】:2022-12-27 21:41:51
【问题描述】:

I have a class library created with dot net core 3.1. There are two files which I am using for logging and reading appsetting.json file. For this I am using two custom class files respectively for logging and reading appesttings.json file. Here is sample code for same.

1)Logging (File 1:CustomLogger.cs)

2)Reading appsetting.json (File 2: ConfigHelper.cs)

Now I am consuming my class library by adding project reference in another separate console application.

When I run my console application, I am getting an exception in GetCurrentSettings method where I am not able to reach to appsetting.json file. Instead it is trying to find that file in current console application of bin folder.

So How could I read appsetting.json values from base project.

【问题讨论】:

    标签: c# class-library


    【解决方案1】:

    The error you are getting is because the appsettings SHOULD be copied to the bin folder as part of the build.

    appsettings.X.json should have a setting:

    Copy to output directory: "Copy if newer"

    【讨论】:

      猜你喜欢
      • 2019-09-29
      • 2012-10-05
      • 2022-12-02
      • 2022-12-02
      • 1970-01-01
      • 2022-12-02
      • 2022-12-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多