- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我使用下面的代码在我的 .Net-Core 1.2 环境中添加 CommandLine,我可以使用像 dotnet run --urls "http://a.cn.com:5000"--environment 这样的命令行“生产”
。
public static void Main(string[] args)
{
var config = new ConfigurationBuilder()
.AddJsonFile("hosting.json", optional: true)
.AddCommandLine(args)
.Build();
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.UseStartup<Startup>()
.UseConfiguration(config)
.Build();
host.Run();
}
迁移到 .net core 2.0 后就变成这样了
public static void Main(string[] args)
{
BuildWebHost(args).Run();
}
public static IWebHost BuildWebHost(string[] args)
{
return WebHost.CreateDefaultBuilder(args)
.ConfigureLogging((context, logging) =>
{
logging.AddSerilog();
})
.UseStartup<Startup>()
.Build();
}
我使用相同的命令行,它失败了。.net core 2.0 如何添加命令?
供应:2017.08.17下面的 launchsetting.json :
{
"iisSettings": {
"windowsAuthentication": false,
"anonymousAuthentication": true,
"iisExpress": {
"applicationUrl": "http://localhost:5005/",
"sslPort": 0
}
},
"profiles": {
"IIS Express": {
"commandName": "IISExpress",
"launchBrowser": true,
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
}
},
"Robert.Project.Web": {
"commandName": "Project",
"environmentVariables": {
"ASPNETCORE_ENVIRONMENT": "Development"
},
"applicationUrl": "http://localhost:5006"
}
}
}
我期望的听力是正在收听http://a.cn.com:5000
我得到的是:
并且我们不应该在 Program.cs
文件中添加任何其他代码,因为 CreateDefaultBuilder 包含 addCommandLine。更多详情,您可以查看WebHost.cs#L177
供应 2017 0817 17:44 UTC+8
[::] is the IPv6 equivalent of IPv4 0.0.0.0.
最佳答案
直接使用UseConfiguration
设置args填充的url地址:
public static IWebHost BuildWebHost(string[] args)
{
var config = new ConfigurationBuilder().AddCommandLine(args).Build();
return WebHost.CreateDefaultBuilder(args)
.UseConfiguration(config)
.UseStartup<Startup>()
.Build();
}
And we should not add any other code in Program.cs file, cause CreateDefaultBuilder is contain addCommandLine. for more detail, you can see WebHost.cs#L177
这不完全正确,因为链接的 CreateDefaultBuilder
实现使用 ConfigureAppConfiguration
方法,而不是 UseConfiguration
。并且有区别(来自相关的 Github issue ):
The
ConfigureAppConfiguration
was intended to configure theIConfiguration
in the application services whereasUseConfiguration
is intended to configure the settings of theWebHostBuilder
. Since the url address is a setting on theWebHostBuilder
onlyUseConfiguration
will work here.Note that the WebHostBuilder's configuration is added to the application's configuration but the converse is not true; configuring the application's configuration does not affect the WebHostBuilder's configuration.
关于c# - WebHostBuilder。如何在 .NET-Core 2.0 中使用 CommandLine 设置 url 地址?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45710570/
Swift 标准库将 CommandLine 声明为枚举。 /// Command-line arguments for the current process. public enum Comman
我正在尝试将预构建 shell 脚本添加到我的 gradle/Android-Studio 构建中。我已将以下内容添加到 app/build.gradle: task prePreBuild << {
我正在尝试使用 System.CommandLine,但无法让我的处理程序查看我传入的任何值。我尝试了最简单的命令行程序只是为了查看是否有任何值成功了,但到目前为止我还没有成功。我的目标是 .NET
在 gradle 中,有什么理由不使用 Groovy 的 .execute() 函数来运行命令行进程?我知道“gradle”方式是来自 Exec 的命令行。但感觉 .execute() 提供了更多的灵
使用根命令: new RootCommand { new Option("--myoption") }; 你怎么区分 ./myapp 和 ./myapp --myoption "" ? 我最初
我确信这会很简单,但找不到任何文档或解决方案。 我正在尝试使用 gcloud 编写脚本以在我的 GCP 实例中执行一些操作。 无论如何只能通过命令行使用 gcloud 登录/验证吗? 谢谢 最佳答案
在 $HOME/.gradle/init.gradle我有: gradle.buildFinished { buildResult -> commandLine 'bash', "blah b
我正在使用来自 nuget 的命令行库 v 1.9.71.2。不幸的是,文档不是最新的,而且我不了解用于此库的高级 C# 语言结构,因此我无法仅通过查看库中可用的接口(interface)来提出可行的
对于单元测试,我想模仿不同的命令行参数。如何在运行时将 commandLine args 修改为我的程序(环顾四周但找不到技巧)?基本上,我试图找到一种方法来修改 READONLY 属性 Enviro
我有一个 C++ 应用程序,它使用 CCommandLineInfo 来解析命令行参数。 其中一个参数是我们在应用程序启动后使用 CryptProtectMemory 在内存中加密的密码。 那时我想摆
我已经使用 CommandLine 库来解析它通过字符串类型、int 类型、bool 类型但它不能通过字节类型,我有一个异常 “Bad default value.” [Option("m",
我有一个项目正在向 Chrome 浏览器添加一些特定的标志(命令行),问题是我通过创建一个新的 Chrome 快捷方式来执行此操作,其中包含我想要执行的标志。 在过去的几天里,这个解决方案变得过于肤浅
我正在尝试使用 System.CommandLine 并且我已经安装了 nuget 包: Install-Package System.CommandLine -Version 2.0.0-beta1
我想在 gradle 任务中从命令行执行一些命令(例如打印目录中的所有文件): task dir(type: Exec) { def adbCommand = ["dir", "*.*"] c
使用 Command Line Parser Library , 有没有办法标记一组 say 3 选项并准确地制作所需的三个选项之一? 所以有这些选择: [Option("list-plugins",
$ mongo MongoDB shell version: 2.0.0 connecting to: test > use admin switched to db admin > db.auth(
我想使用 org.apache.commons.exec Java 库来调用可执行文件。 CommandLine对象防止命令行注入(inject)?例如,如果我调用: String singleStr
打印格式字符串如何作为参数传递? 例子.cpp: #include int main(int ac, char* av[]) { printf(av[1],"anything");
请在下面找到我的 dom xml 示例。我正在运行命令 virsh create 并收到此错误: Unable to open file 这个文件的权限都很好。 qemu:commandline下的
起初:我知道命令行中tsc和tsc -w的区别。这不是问题,而是一种特殊情况: 在 VS Code 的 tsconfig 中,我通过设置 "watch":true 启用了观察器。这是绝对想要的。但是现
我是一名优秀的程序员,十分优秀!