是否可以静默运行 .NET Core 控制台应用程序(隐藏控制台窗口)? [英] Is it possible to run a .NET Core console application silently (hide console window)?
问题描述
我正在尝试为自己自动执行一些任务,并编写了一些 .NET Core 1.0 控制台应用程序.其中之一是 BrowserRouter - 一个简单的应用程序,它基于 URL 模式决定在我点击 HTTP(S) 链接时打开哪个浏览器/浏览器配置文件.
I'm trying to automate some tasks for myself and I wrote a few .NET Core 1.0 console applications. One of them is BrowserRouter - a simple application which, based on a URL pattern, decides which browser / browser profile to open when I click on HTTP(S) links.
这工作正常,但总是有控制台窗口出现并立即消失.
That works fine, but there is always the console window which appears and immediately disappears.
有没有办法静默运行 .NET Core 控制台应用程序(隐藏控制台窗口)?
Is there a way to run the .NET Core console application silently (hiding the console window)?
我知道在完整的 .NET Framework 中可以将输出类型更改为 Windows 应用程序,但是这不适用于 .NET Core.
I know in the full .NET Framework it is possible to change the output type to Windows Application, but that's not available (yet?) for .NET Core.
推荐答案
Update 2018:在 .NET Core 3.0+ 中,您将能够设置
.
Update 2018: In .NET Core 3.0+, you will be able to set <OutputType>WinExe</OutputType>
inside of the csproj file.
目前,这不是直接可能的,因为 Windows EXE 文件包含一个标志,指示它是否是控制台".或GUI"Windows 甚至在启动应用程序之前评估的应用程序.但是,可以使用 editbin.exe
(据我所知随 Visual Studio 的 C++ 构建工具一起提供)更改此标志.
Currently, this is not directly possible out of the box because Windows EXE files contain a flag indicating if it is a "console" or "GUI" application that Windows evaluates even before starting the application. However, this flag can be changed using editbin.exe
(ships with Visual Studio' C++ build tools as far as I know).
以此为基础,您可以创建一个自包含的 .NET Core 应用程序(从 project.json
和添加运行时部分)以便您的项目输出包含一个实际的 .exe
文件,并添加一个调用 editbin.exe/subsystem:windows yourapp.exe
的构建后脚本.
Building on this, you could create a self-contained .NET Core application (removing the "type": "platform"
from the project.json
and adding a runtimes section) so your project output includes an actual .exe
file and add a post-build script that invokes editbin.exe /subsystem:windows yourapp.exe
.
这篇关于是否可以静默运行 .NET Core 控制台应用程序(隐藏控制台窗口)?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!