According to the docs for .NET Core 5, there's a method SetBasePath and it's widely used in a bunch of blogs (example 1, example 2, example 3 etc.). There's no notion of it being a weird gotcha or such. However, when I try the syntax below, it's marked red and claimed not to be there.
using System;
using Microsoft.Extensions.Configuration;
static void Main(string[] args)
{
string path = AppDomain.CurrentDomain.BaseDirectory;
IConfigurationBuilder builder = new ConfigurationBuilder();
builder.SetBasePath(path);
}
I'm not sure why this happens not what to do about it.
Steps to reproduce:
- Create a vanilla console application in .NET Core 5 in C#.
- Paste in the code in Program.cs replacing the file's contents.
- Try to compile or execute.
The error received is like this.
Error CS1061
'ConfigurationBuilder' does not contain a definition for 'SetBasePath' and no accessible extension method 'SetBasePath' accepting a first argument of type 'ConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)
As far i can understand, I have all the prerequisites in place.
question from:
https://stackoverflow.com/questions/65873061/setbasepath-not-present-in-configurationbuilder-under-net-core-5 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…