简体   繁体   English

为什么 SetBasePath 在 .NET Core 3.1 中不起作用? 我试过添加 nuget 包,但它不起作用

[英]Why does SetBasePath not work in .NET Core 3.1? I've tried adding nuget packages, but it doesn't work

Error CS1061错误 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?) “ConfigurationBuilder”不包含“SetBasePath”的定义,并且找不到接受“ConfigurationBuilder”类型的第一个参数的可访问扩展方法“SetBasePath”(您是否缺少 using 指令或程序集引用?)

screenshot截屏

I've installed these packages:我已经安装了这些软件包:

Microsoft.Extensions.Configuration;
Microsoft.Extensions.Configuration.Json;
Microsoft.Extensions.Configuration.FileExtensions

The code is working in .NET Core 2.2 but not in .NET Core 3.1.该代码适用于 .NET Core 2.2,但不适用于 .NET Core 3.1。

Code is here:代码在这里:

using Microsoft.Extensions.Configuration;
using System;
using System.IO;

namespace Core.Logic.Mappers
{
    public class MappingProfile : Profile
    {
        public MappingProfile()
        {
            IConfigurationRoot configuration = new ConfigurationBuilder().SetBasePath(Directory.GetCurrentDirectory())
                                                                         .AddJsonFile("appsettings.json")
                                                                         .Build();

Finally, after couple days I found solution:最后,几天后我找到了解决方案:

I have multiple-projects in my solution, so I was installing我的解决方案中有多个项目,所以我正在安装

    Microsoft.Extensions.Configuration.Json;

to other project.到其他项目。 Noobie :D诺比 :D

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 为什么 NuGet 包 NLog 不适用于 .NET Core? - Why doesn't NuGet package NLog work for .NET Core? .Net Core 3.1 中的 Worker Service 安装后不起作用 - Worker Service in .Net Core 3.1 doesn't work after installation 无法使Delete方法起作用。 我试过调试,它似乎甚至没有直接指向该方法 - Cannot get Delete method to work. I've tried debugging and it doesn't seem to even direct to the method VS Code Intellisense不适用于nuget包 - VS Code Intellisense doesn't work for nuget packages ASP.NET Core 2.2 Razor Pages 为什么 OnPost() 有效,而 OnPostAsync() 无效? - ASP.NET Core 2.2 Razor Pages why does OnPost() work, but OnPostAsync() doesn't? 为什么 asp.net 内核 model 绑定不起作用? - Why doesn't asp.net core model binding work? .Net Core / Azure Web Job示例为何不起作用? - Why doesn't the .Net Core / Azure Web Job example work? .Net Core 3.1 Jwt Validate Issuer 似乎不起作用 - .Net Core 3.1 Jwt Validate Issuer does not seem to work Json 反序列化动态在 .NET Core 3.1 中不起作用 - Json deserialize dynamic does not work in .NET Core 3.1 NET Core 3.1 MVC 输入验证不起作用 - NET Core 3.1 MVC Input Validation does not work
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM