I have this line
string sConnectionString = ConfigurationManager.ConnectionStrings["Hangfire"].ConnectionString;
And it requires to include System.Configuration
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
?
You can also right-click the project node and select Add > Project Reference. If you see a References node in Solution Explorer, you can use the right-click context menu to choose Add Reference. Or, right-click the project node and select Add > Reference.
Add Class Library Reference To use a class library in your application, you must add a reference to the library to access its functionality. Right click on the project name of your console app in Solution Explorer and select Add ->Reference option.
In the Project Designer, click the References tab. Click the Add button to open the Add Reference dialog box. In the Add Reference dialog box, select the tab indicating the type of component you want to reference. Select the components you want to reference, and then click OK.
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
.
Assuming your Hangfire
connection-string is defined in your appsettings.json
:
{
"ConnectionStrings": {
"HangFire": "yourConnectionStringHere"
}
}
You can read it in your 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");
}
}
Also, you're gonna need the Microsoft.Extensions.Configuration.Json
package to use the AddJsonFile()
extension method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With