当我尝试在ConfigurationBuilder上调用AddCommandLine()函数时,得到的语法错误是指定
项目属于.NetStandard 2.0
环境:
代码段:
var config = new ConfigurationBuilder()
.AddEnvironmentVariables()
.AddCommandLine(args)
.Build();
注意:尝试使用Microsoft.Extensions.Configuration的ConfigurationBuilder
答案 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一起使用时,可以添加以下元软件包:
Microsoft.AspNetCore.App metapackage for ASP.NET Core 2.1
通过answer记录原始Kirk Larkin