如何在ASP.NET Core项目中包括对程序集的引用 [英] How to include reference to assembly in ASP.NET Core project
问题描述
我有这行
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 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屋!