如何在ASP.NET Core项目中包括对程序集的引用 [英] How to include reference to assembly in ASP.NET Core project

查看:679
本文介绍了如何在ASP.NET Core项目中包括对程序集的引用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这行

string sConnectionString = ConfigurationManager.ConnectionStrings["Hangfire"].ConnectionString;

并且它需要包含我必须在项目的哪个位置添加对System.Configuration的引用,因为我找不到在References下执行此操作的经典位置?

In which place of the project I have to add reference to System.Configuration because I cannot find a classic place to do it under References?

推荐答案

您正在关注的教程可能是使用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.

这篇关于如何在ASP.NET Core项目中包括对程序集的引用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆