是否可以静默运行.NET Core控制台应用程序(隐藏控制台窗口)? [英] Is it possible to run .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 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 full .NET Framework it is possible to change the output type to Windows Application but that's not available (yet?) for .NET Core.
推荐答案
更新2018年:在.NET Core 3.0+中,您将能够在csproj文件中设置< OutputType> WinExe< / OutputType>
。
Update 2018: In .NET Core 3.0+, you will be able to set <OutputType>WinExe</OutputType>
inside of the csproj file.
当前,这不是<因为Windows exe文件包含一个标志,指示Windows是在启动应用程序之前对其进行评估的控制台或 GUI应用程序,所以直接使用em>可能是直接可用的。但是,可以使用 editbin.exe
(带有VS'C ++构建工具afaik的船)更改此标志。
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" app that windows evaluates even before starting the application. However this flag can be changed using editbin.exe
(ships with VS' C++ build tools afaik).
构建在此基础上,您可以创建一个自包含的.NET Core应用程序(从 project.json中删除
并添加一个运行时部分),因此您的项目输出将包含实际的 type: platform
.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屋!