Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide kestrel console? [duplicate]

I have a .net core app that I want to run in background, but I can't seem to get rid of the console window of Kestrel. Is there any way to hide it without running the app as a windows service? I've tried to remove any reference related to Logger, it didnt help.
here is my 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();

Thanks

like image 967
Yuval Perelman Avatar asked Jul 19 '17 20:07

Yuval Perelman


1 Answers

the solution was using editbin.exe as described here https://github.com/AvaloniaUI/Avalonia/wiki/Hide-console-window-for-self-contained-.NET-Core-application

editbin.exe /subsystem:windows yourapp.exe
like image 68
Yuval Perelman Avatar answered Oct 11 '22 07:10

Yuval Perelman