且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何在ASP.NET Core项目中包括对程序集的引用

更新时间:2023-02-15 19:26:59

您正在关注的教程可能是使用Asp.Net Core,目标是能够依赖System.Configuration的完整.Net Framework(4.6).不是可移植的,CoreFX不支持.)

The tutorial your're following is probably using Asp.Net Core targeting the full .Net Framework (4.6) that is capable of relying on System.Configuration (that is not portable and not supported in CoreFX).

.Net Core项目(跨平台)使用基于

.Net Core projects (being cross-platform) use a different configuration model that is based on Microsoft.Extensions.Configuration rather than on System.Configuration.

假设在您的appsettings.json中定义了Hangfire连接字符串:

Assuming your Hangfire connection-string is defined in your appsettings.json:

{
     "ConnectionStrings": {
         "HangFire": "yourConnectionStringHere"
     }
}

您可以在Startup.cs中阅读它:

public class Startup
{
    public Startup(IHostingEnvironment env)
    {
        var builder = new ConfigurationBuilder()
            .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)

        this.Configuration = builder.Build();

        var hangFireCS = this.Configuration.GetConnectionString("HangFire");
    }
}

此外,您将需要 Microsoft.Extensions.Configuration.Json 包以使用AddJsonFile()扩展方法.

Also, you're gonna need the Microsoft.Extensions.Configuration.Json package to use the AddJsonFile() extension method.