4

While i'm trying to invoke AddCommandLine() function on ConfigurationBuilder am getting syntax error that specifying

  • IConfigurationBuilder doesn't a definition or doesnot contain an extension method AddCommandLine accepting the first argument as IConfigurationBuilder

Project was of .NetStandard 2.0

Environment:

  • .net core 2.1
  • .net Standard 2.0
  • OS : window 10

code snippet :

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

Note: Tried to use ConfigurationBuilder from Microsoft.Extensions.Configuration

leox
  • 1,315
  • 17
  • 26

1 Answers1

13

When getting the following error:

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

Run the following on the Nuget Package Manager Console in Visual Studio

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

Or run the following using the dotnet cli:

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

Reference errors for various extensions may be common when working with GenericHost

When working with GenericHost it may be an option to add a metapackage such as:

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

Documenting original answer by Kirk Larkin

stormwild
  • 2,855
  • 2
  • 31
  • 38