是否可以静默运行.NET Core控制台应用程序(隐藏控制台窗口)? [英] Is it possible to run a .NET Core console application silently (hide console window)?

查看:172
本文介绍了是否可以静默运行.NET Core控制台应用程序(隐藏控制台窗口)?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图为自己自动化一些任务,并编写了一些.NET Core 1.0控制台应用程序.其中之一是BrowserRouter,这是一个简单的应用程序,它基于URL模式,可以确定当我单击HTTP(S)链接时要打开哪个浏览器/浏览器配置文件.

那很好,但是总是有控制台窗口出现,然后立即消失.

是否有一种方法可以静默运行.NET Core控制台应用程序(隐藏控制台窗口)?

我知道在完整的.NET Framework中,可以将输出类型更改为 Windows应用程序,但这对于.NET Core还不可用(还可以吗?).

解决方案

更新2018 :在.NET Core 3.0+中,您将可以在csproj文件中设置<OutputType>WinExe</OutputType>./p>

当前,这是不可能直接实现的,因为Windows EXE文件包含一个标志,指示它是否为控制台".或"GUI" Windows甚至在启动应用程序之前对其进行评估的应用程序.但是,可以使用editbin.exe(据我所知Visual Studio Studio C ++生成工具附带)来更改此标志.

在此基础上,您可以创建一个独立的.NET Core应用程序(从project.json中删除"type": "platform"并添加运行时部分),以便您的项目输出包括实际的.exe文件并添加一个帖子. -build脚本,调用editbin.exe /subsystem:windows yourapp.exe.

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.

Is there a way to run the .NET Core console application silently (hiding the console window)?

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: In .NET Core 3.0+, you will be able to set <OutputType>WinExe</OutputType> inside of the csproj file.

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).

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆