尽管需要使用声明和扩展,但仍无法进行函数调用 [英] Can't make a function call in in spite of the using-statement and extension needed
问题描述
因此,我希望能够从终端运行 dotnet
(.net核心mvc-project)时选择我的环境。我发现了此帖子,并想到了简而言之,第二高的答案是一种巧妙的解决方法:
用以下内容代替Program类主体:
私有静态只读字典< string,string>默认值=
新的Dictionary< string,string> {
{WebHostDefaults.EnvironmentKey, development}
};
公共静态无效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();
}
然后运行:
dotnet运行环境=开发
dotnet运行环境=暂存
所以我粘贴了它,并说我需要使用Microsoft.Extensions.Configuration; $>
c $ c>
仍然收到此错误消息:
' IConfigurationBuilder'不包含
'AddCommandLine'的定义,找不到扩展方法'AddCommandLine'
接受类型为'IConfigurationBuilder'的第一个参数
(您是否缺少using指令或
程序集引用?)
我有点不知所措,原因可能是问题。我的意思是,这是定义 AddCommandLine(IConfigurationBuilder,String [])
的名称空间为
Microsoft.Extensions.Configuration
?
尽管命名空间是 Microsoft.Extensions.Configuration
,扩展名在 Microsoft.Extensions.Configuration.CommandLine
程序集中,该程序集在 Microsoft.Extensions.Configuration.CommandLine
包。您需要在该软件包上添加一个依赖项。
So I wanted to be able to choose my environment when running dotnet
(an .net core mvc-project) from the terminal. I found this post and thought the second highest answer was a neat way of solving it, in short:
Replacing the Program class body with the following:
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();
}
Then running:
dotnet run environment=development
dotnet run environment=staging
So I pasted it, and it said I need to add a using statment
using Microsoft.Extensions.Configuration;
Still got this error message:
'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?)
I'm a bit at loss for what could be the problem. I mean, here's the definition of AddCommandLine(IConfigurationBuilder, String[])
with namespace Microsoft.Extensions.Configuration
?
Although the namespace is Microsoft.Extensions.Configuration
, the extension is in the Microsoft.Extensions.Configuration.CommandLine
assembly, which is in the Microsoft.Extensions.Configuration.CommandLine
package. You need to add a dependency on that package.
这篇关于尽管需要使用声明和扩展,但仍无法进行函数调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!