我有一个.net核心应用程序,我想在后台运行,但似乎无法摆脱Kestrel的控制台窗口。有没有办法隐藏它,而无需将应用程序作为Windows服务运行?我试图删除任何有关记录器的参考,它没有帮助。
这里是我的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();
感谢
是不是只是调试解决方案? –
nope。我添加了Program.Main代码,并且当我以发行模式构建并运行.exe文件 –