找不到AddCommandLine .netcore 2.1

时间:2018-08-03 15:44:45

标签: asp.net-core-2.1 .net-standard-2.0

当我尝试在ConfigurationBuilder上调用AddCommandLine()函数时,得到的语法错误是指定

  • IConfigurationBuilder没有定义或不包含接受第一个参数作为IConfigurationBuilder的扩展方法AddCommandLine

项目属于.NetStandard 2.0

环境:

  • .net核心2.1
  • .net Standard 2.0
  • 操作系统:窗口10

代码段:

var config = new ConfigurationBuilder()
            .AddEnvironmentVariables()
            .AddCommandLine(args)
            .Build();

注意:尝试使用Microsoft.Extensions.Configuration的ConfigurationBuilder

1 个答案:

答案 0 :(得分:7)

出现以下错误时:

'IConfigurationBuilder' does not contain a definition for 'AddCommandLine' and no extension method 'AddCommandLine' accepting a first argument of type 'IConfigurationBuilder'

在Visual Studio的Nuget软件包管理器控制台上运行以下命令

Install-Package -ProjectName MyProj Microsoft.Extensions.Configuration.CommandLine

或使用dotnet cli运行以下命令:

dotnet add myproj.csproj package Microsoft.Extensions.Configuration.CommandLine

使用GenericHost

时,各种扩展名的参考错误可能很常见。

与GenericHost一起使用时,可以添加以下元软件包:

Microsoft.AspNetCore.App metapackage for ASP.NET Core 2.1

通过answer记录原始Kirk Larkin