如何隐藏kestrel控制台?

时间:2017-07-19 20:25:58

标签: c# asp.net-core-mvc .net-core kestrel

我有一个.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();

由于

1 个答案:

答案 0 :(得分:4)