【发布时间】:2017-07-19 20:25:58
【问题描述】:
我有一个想要在后台运行的 .net 核心应用程序,但我似乎无法摆脱 Kestrel 的控制台窗口。有没有办法在不将应用程序作为 Windows 服务运行的情况下隐藏它?我已尝试删除与 Logger 相关的任何参考,但没有帮助。
这是我的 Program.Main:
var config = new ConfigurationBuilder()
.SetBasePath(Directory.GetCurrentDirectory())
.AddJsonFile("hosting.json", optional: true)
.Build();
var hostingUrl = config.GetValue<string>("HostingUrl");
if (string.IsNullOrEmpty(hostingUrl))
{
var xmlString = File.ReadAllText(Consts.WebHostBaseFolder + "\\web.config");
var confDoc = XDocument.Parse(xmlString);
hostingUrl = confDoc.Element("configuration").Element("appSettings")?.Elements("add")?.FirstOrDefault(e => e.Attribute("key").Value == "HostingUrl")?.Attribute("value")?.Value ?? "";
}
var host = new WebHostBuilder()
.UseKestrel()
.UseContentRoot(Consts.WebHostBaseFolder)
.UseStartup<Startup>()
.UseUrls(hostingUrl)
.Build();
host.Run();
谢谢
【问题讨论】:
-
那不只是调试吗?
-
不。我添加了 Program.Main 代码,当我在发布模式下构建并运行 .exe 文件时,它也会显示控制台
标签: c# asp.net-core-mvc .net-core kestrel