如何隐藏红隼控制台?
how to hide kestrel console?
我有一个 .net 核心应用程序,我想 运行 在后台运行,但我似乎无法摆脱 Kestrel 的控制台 window。有什么方法可以隐藏它而不 运行 将应用程序作为 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();
谢谢
解决方案使用的是 editbin.exe,如此处所述 https://github.com/AvaloniaUI/Avalonia/wiki/Hide-console-window-for-self-contained-.NET-Core-application
editbin.exe /subsystem:windows yourapp.exe
我有一个 .net 核心应用程序,我想 运行 在后台运行,但我似乎无法摆脱 Kestrel 的控制台 window。有什么方法可以隐藏它而不 运行 将应用程序作为 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();
谢谢
解决方案使用的是 editbin.exe,如此处所述 https://github.com/AvaloniaUI/Avalonia/wiki/Hide-console-window-for-self-contained-.NET-Core-application
editbin.exe /subsystem:windows yourapp.exe