Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/37.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Can';尽管使用了所需的语句和扩展,但仍不能进行函数调用_C#_Asp.net_.net Core - Fatal编程技术网

C# Can';尽管使用了所需的语句和扩展,但仍不能进行函数调用

C# Can';尽管使用了所需的语句和扩展,但仍不能进行函数调用,c#,asp.net,.net-core,C#,Asp.net,.net Core,因此,我希望能够在从终端运行dotnet(一个.net核心mvc项目)时选择我的环境。简言之,我发现并认为第二高的答案是一种巧妙的解决方法: 将程序类主体替换为以下内容: private static readonly Dictionary<string, string> defaults = new Dictionary<string, string> { { WebHostDefaults.EnvironmentKey, "development" } };

因此,我希望能够在从终端运行
dotnet
(一个.net核心mvc项目)时选择我的环境。简言之,我发现并认为第二高的答案是一种巧妙的解决方法:

将程序类主体替换为以下内容:

private static readonly Dictionary<string, string> defaults =
new Dictionary<string, string> {
    { WebHostDefaults.EnvironmentKey, "development" }
};

public static void Main(string[] args)
{
    var configuration =
        new ConfigurationBuilder()
            .AddInMemoryCollection(defaults)
            .AddEnvironmentVariables("ASPNETCORE_")
            .AddCommandLine(args)
            .Build();

    var host = new WebHostBuilder()
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}
所以我粘贴了它,它说我需要添加一个using语句

使用Microsoft.Extensions.Configuration

仍然收到此错误消息:

'IConfigurationBuilder' does not contain a definition for
'AddCommandLine' and no extension method 'AddCommandLine' 
accepting a first argument of type 'IConfigurationBuilder' 
could be found (are you missing a using directive or an 
assembly reference?)
我对可能出现的问题有点不知所措。我的意思是,
AddCommandLine(IConfigurationBuilder,String[])的定义

带有命名空间
Microsoft.Extensions.Configuration

尽管命名空间是
Microsoft.Extensions.Configuration
,但扩展位于
Microsoft.Extensions.Configuration.CommandLine
程序集中,该程序集位于。您需要添加对该软件包的依赖项。

您使用的是哪个版本的
Microsoft.Extensions.Configuration
?嗯,首先在
ConfigurationBuilder
下出现了红色的波形,然后建议我使用Microsoft.Extensions.Configuration添加
我就是这么做的。我没有想到,但是现在你问我,我看了一下我的
.deps.json
-文件,在
的“microsoft.aspnetcore.hosting/1.1.2”:{“dependencies”:{
有一行写着
“microsoft.Extensions.Configuration”:“1.1.2”,
。所以我想它是1.1.2版?是的,这是版本号。啊,我想我已经知道了-你是否依赖于
Microsoft.Extensions.Configuration.CommandLine
?这就是扩展方法的来源。是的!我运行了
dotnet添加包Microsoft.Extensions.Configuration.CommandLine
,然后是我们讨论的所有问题不幸的是,无论我运行
dotnet运行环境=开发
还是
dotnet运行环境=生产
还是简单地运行
dotnet运行
,它似乎都处于生产模式,尽管我通过f5运行它时它运行在开发模式(根据
launch.json
)的说明。所以我想我学会了一种测试两种模式的方法,尽管不那么优雅。不过我想这是另一个问题,你肯定帮了我这个问题。谢谢!
'IConfigurationBuilder' does not contain a definition for
'AddCommandLine' and no extension method 'AddCommandLine' 
accepting a first argument of type 'IConfigurationBuilder' 
could be found (are you missing a using directive or an 
assembly reference?)