Okay so I have a console application in Windows 11 using .Net-7.0 and not targeting any particular platform
When I go to set the console's window and buffer sizes it does absolutely nothing, and without checking if the operating system is Windows using OperatingSystem.IsWindows()
before calling either Console.SetWindowSize([w], [w])
or Console.SetBufferSize([w], [h])
the IDE throws a warning of CA1416
as it isn't a platform specific call.
I have no problem using the IsWindows()
check as this is just a test application, but I am trying to output the data in a fixed width and height (such as a REPL application would, but without redrawing the screen). Since I cannot set either the window width OR the buffer width through the System.Console
API I would have to implement my own buffer code to accomplish what I am trying to do.
Is this an issue with Windows Terminal vs CMD? How do I accomplish what I am trying to do without bringing in a third party library? Am I stuck having to do some P/Invoke magic to do this?
EDIT: I am unable to change the framework I am targeting at all as the code this program tests requires .Net-7.0
EDIT 2: Upon further diagnosis I have found that a fresh console app targeting .Net Core 3.1 WILL allow me to set the buffer width/height in the following way, however it does NOT modify the window's size at all and does NOT work in .Net-7.0. Only the buffer is actually adjusted, and the call to Console.Clear()
is required to make it actually stick.
Console.SetWindowSize(5,5);
Console.SetBufferSize(5,5);
Console.Clear();