简体   繁体   中英

Display a message in the output window when in non-debug mode (.NET 5)

Often while writing code (graphical application WPF), it becomes necessary to check, for example, the value of an object and display it on the console. Please note that we are talking about the mode without debugging (CTRL + F5). In debug mode, there are many tools for this, including Debug.WriteLine () or Trace.WriteLine (). But debugging is not required every time, more often, during the writing process, it is necessary to run the application without debugging and just check something and display it in the console.

Using .NET Framework 4.8, I was able to select a "console application" (Properties - Application - Console application) and enjoy the output of anything to the console using the good old Concole.WriteLine. However, I switched to .NET 5 and to my surprise I found that I could not select the "console application" and display the information I was interested in. Also, messages are not displayed in VS2019 output window in non-debug mode (Debug constant is defined).

Yes, I know that all these possibilities are there in debug mode (F5), but, again, I don't always want to run it to check the state of an object. What are the ways to display technical information on the screen in non-debugging mode (CTRL + F5) when using .NET 5 (to the Output window or to the console)? Are there possible extensions for this purpose? Thank you.

After setting Output type to "Console Application", you also need to add this to project(.csproj).

<DisableWinExeOutputInference>true</DisableWinExeOutputInference>

For more details, refer to OutputType set to WinExe for WPF and WinForms apps .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM