我继承了一些代码:
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
我认为它源于.net Core 应用程序。首先,我在这一点上苦苦挣扎(从某种意义上说,我无法在 .Net Framework 中编译它):
.SetBasePath(Directory.GetCurrentDirectory())
但我遇到了这个。接受的答案解决了它。现在我正在努力解决这一点(再次在我无法在 .Net Framework 中编译它的意义上)::
.AddJsonFile("appsettings.json")
请问有没有办法解决这个问题(通常我会从 App.Config 获得这样的数据......)?谢谢。
PS:
更多代码加上错误消息:
using Microsoft.Extensions.Configuration;
using System;
using System.IO;
using System.Threading.Tasks;
using Microsoft.Extensions.Configuration.FileExtensions;
using Microsoft.Extensions.Configuration;
namespace SandboxSecurityToken
{
class Program
{
static void Main(string[] args)
{
...
static async Task RunAsync()
{
var builder = new Microsoft.Extensions.Configuration.ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("appsettings.json");
Severity Code Description Project File Line Suppression State
Error CS1061 'IConfigurationBuilder' does not contain a definition for 'AddJsonFile' and no accessible extension method 'AddJsonFile' accepting a first argument of type 'IConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)