2

I have a C# Console app than runs a pre-build step (to get NuGet Packages).

When I am debugging this, I want to pass in a parameter and show the console. When I am not debugging it I don't want to see it. I don't even want it to flash up there for a second.

I have found ways to hide it, after it has shown. But I can't find a way to never make it show unless I am willing to change it from a console app to a Windows app. (Which I would do if I could then find a way to show the Console when needed.)

3

2 Answers 2

2

Build as a Windows application and show the console when you need it. To show the console when needed use P/Invoke to call AllocConsole (pinvoke.net has the declaration you need).

(Console sub-system processes always get a console, their parent process's if there was one, otherwise a new one. This is the way Windows works at a deep level.)

Sign up to request clarification or add additional context in comments.

2 Comments

aren't all applications windows applications? ;)
He's talking about the name of the setting in Project + Properties, Application tab.
-1

Use FreeConsole WINAPI function:

http://pinvoke.net/default.aspx/kernel32/FreeConsole.html

Another solution is to simply switch to a WinForms application as project type. No console will be allocated then (and you do not need to show a form).

2 Comments

FreeConsole has the same problems as ShowWindow(handle, SW_HIDE). It only helps for an already existing console. I want it to never appear in the first place.
Read the "Another solution" part. The fact is that you can never hide a console from start when you have specified "console application" as project type.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.