Have a look at the picture. No matter where i put console.writeline, nothing is showing in output. Where could be a mistake? Is something wrong with my output editor or what?
Use Debug.WriteLine to write to the Output window as you want.
See also What's the difference between Console.WriteLine() vs Debug.WriteLine()?
So you have 2 questions instead of one: your main one and the comment "How can i display console window instead of Output window?"
You can write to VS output by using Debug.WriteLine. This requires System.Diagnostics namespace.
You can also run console window alongside with your windows application. Right click the project in Solution Explorer, select Properties, change Output Type to "Console Application" like this.
Related
I am new to Visual Studio Express 2015 and whole C# stuff (I come from the JAVA world).
I want to see some test string output (like checking variable values etc.) I am sending with Debug.WriteLine() during Debug mode run (F5), but the output window disappears immediately (is replaced by split dual windows). Yet when I close the running app, output window shows up back again WITH MY TEST STRING OUTPUT from Debug.WriteLine(); there - how come?
This is what I call "output window" (sorry, don't know how to call it when it has written Output on it, really...)
This is what I see when I test/run (F5) my app ("output" window is gone):
And this is what I see when I stop/close my app - "output" window is back again also with my test string I sent with Debug.WriteLine():
How can I run my app in Debug mode and also make that output window still visible during the run/test, so I could see my string output in realtime?
I need to see some test values I am sending to the output, or is there some other way how to do this in C#/Visual Studio Express 2015?
In JAVA I use NetBeans and I use Output window/CMD exactly for this, so I thought this is its equivalent. And as I see the output actually is there, it probably is, right?
Just to clarify even more: I am not creating console app that runs in CMD window, I just need to see that test output somewhere and I thought - being completely new to C# coming from JAVA - that the Output window is the place where I can see it.
Like when you C# guys need to see some test values in realtime during the app run/test, how do you do that - where your output goes? Or are you telling me there is nothing like this in Visual Studio GUI (I don't think so as I see after the app is closed my test value is present in that "output" window - the window is just not there during the app run, so...)?
I have the namespace using System.Diagnostics; in place, yet it still act as described above: in Debug mode the output window disappears, so I don't know what the string output is (have no clue how to make the window being visible still) and only comes back again once the app is closed (then there is my string output presented in the output window), with the Release mode the output window is there but no string output is displayed - it stays completely empty during the app run/test.
You just need to enable it..through the Debug->Windows->Output
How do you print or output text in Monogame?
I googled how to display text in monogame and was led to this:
Debug.WriteLine
Which says: "By default, the output is written to an instance of DefaultTraceListener."(and that page just confused me more).
So, if someone could direct me to a method of displaying DefaultTraceListener, or another method of outputting text in monogame, I would appreciate it.
I found it!
Using Debug.WriteLine writes to the debugger, which is in the output window in Visual Studio(by default at the bottom). It appears when you close the program(press F5 to start, Esc to close) by default in an OpenGL project.
If you like, you can use Console.WriteLine like you would in a normal C# console application, assuming you're developing a desktop application. There are a couple of steps.
Open the Properties for your MonoGame project
Select the Application tab
Change the Output Type to Console Application.
Your application should run as normal, only a console window should appear when you start the game.
Alternatively, you can use Debug.WriteLine, which will write to the output window in Visual Studio (it should appear when you start debugging your game).
If you use the standard Debug.WriteLine or Trace.WriteLine, then output goes to the default trace listener which can be viewed in the Visual Studio output window. Outside of Visual Studio, you can use programs such as DebugView (SysInternals) or LogFusion (Binary Fortress) to display the output. DebugView even has a feature for viewing debug output from a remote machine.
There are other trace listeners that can send output to a file, or to the Windows event log, or you can write your own trace listeners fairly easily.
You could also consider using a ready-made logging framework such as NLog, which would give you a great deal of flexibility. I have found in practice that using NLog turns out to be a lot easier than the built in stuff in .NET, because of the way it lets you easily reconfigure things and control/filter the output in a much more flexible way.
I know this has been answered, but if anyone else stumbles upon this, you can also use Console.Write(thing in here); or Console.WriteLine(thing in here); to write to the console window. WriteLine adds a line ending and Write does not.
I've only used Visual Studio a handful of times.
Can I make an executable with a custom icon that strictly opens a URL in a web browser?
I am assuming Visual Studio will be the best tool to help me achieve this, although I am open to better options.
It has to have a custom icon and be a stand alone file.
Thanks.
if you don't need it to be an executable you could quickly create a windows shortcut.
http://support.microsoft.com/kb/140443
You can personalize the icon too.
As PrashantGupta has pointed out you can only use a subsets of windows icons if you want it to be a single file.
Sure,
Just write a single line console app with this as your code
System.Diagnostics.Process.Start("http://my.url.com");
You can configure an icon from within visual studio easily too.
Sure, did I get this right: You need an EXE with custom icon and launches a URL?
If you choose C# as your development language the following code will achieve what you want:
namespace URLLauncher
{
class Program
{
static void Main(string[] args)
{
System.Diagnostics.Process.Start("http://www.google.com/");
}
}
}
Changing the icon is also quite straightforward in visual studio as well. See this: Adding an icon to my finished application
Also try not to make your application a "Console" application as that will pop up a "black console window" when you launch the app if you need a double-click interface from the user (which I infer from your wanting an ICON).
Hope this helps.
If you decide to go the C++ route, passing a URL to the ShellExecute function will let you launch a website using the user's preferred browser.
See http://support.microsoft.com/kb/224816
And you don't really need anything from the C or C++ runtime for this, so compile with /NODEFAULTLIB use the /ENTRYPOINT linker option to skip all that, make your executable truly tiny, and have very few dependencies (meaning none that aren't included in every version of Windows since 95). It'll start faster too, not needing to run .NET or any library initialization code.
Add your icon in the usual way using the Resource Compiler.
Solves the problem, not necessarily with the requested tool
While we are at-it, so to speak, I thought someone must have invented this wheel before, so if you are not interested in any development what-so-ever (check licenses before use tho), here are some online tools to do what you want:
Web shortcut producer
Remember to scan the EXE for for malware. Hope it helps :-)
The Visual Studio route has a lot of advantages and will work for this situation. Although, it is overkill for the project I am working on.
I have chosen to go with this solution:
Build a .bat file with the command:
start http://www.google.com
Then use a bat to exe converter which allows icon assignment.
Worked like a charm and quick.
I am trying to self teach myself C# and wondering if anyone can help me with what seems to be a basic C# question. I created a C# file with this code, started debugging but don’t see “Hello World” anywhere.
using System;
class Hello
{
static void Main() {
Console.WriteLine("hello, world");
}
}
http://msdn.microsoft.com/en-us/library/aa664628(v=vs.71).aspx
So I guess my question is this. Where should I expect to see “Hello World”? I have checked the Console and the Browser. Is there some setup that needs to be done to properly debug C# files. I am probably missing the big picture as to how C# works. I am use to PHP where I can just do something like this...
<?php
include 'my file';
echo 'my file included';
?>
Any help would be much appreciated. Thanks.
EDIT:
Thanks everybody for all of the help. You have all helped me understand and realize a number of things about C# / .NET. After extensive troubleshooting it is evident that the problem is not a mater of the debugging working, but the fact that my C# file doesn't appear to be properly hooked/included (not sure what its called in .NET terms) to the rest of the project. Anyways I am accepting keyboardP's answer as he answered first and technically gave me all the right answers. Also thanks to dasblinkenlight who was also extra helpful.
Additional Solution:
After insight from SO users. This article helped point me in the right direction.
http://www.asp.net/mvc/tutorials/getting-started-with-aspnet-mvc3/cs/intro-to-aspnet-mvc-3
I'm guessing it's because the command prompt window is immediately closing. You can avoid this by adding Console.ReadLine(); after your WriteLine statement. This will wait for you to press return before closing the prompt window.
Alternatively, assuming you're using Visual Studio, you can run the build without a debugger attached by pressing CTRL + F5.
Edit - Based on the extra information added that you're using ASP.NET and not a console application.
Firstly, what are you trying to achieve? If you want to output debug information, then you can Debug.WriteLine instead of Console.WriteLine
System.Diagnostics.Debug.WriteLine("Hello World");
This will output the text to the "Output" window at the bottom of Visual Studio (by default).
Edit 2 Since you just want to write random text to the page, you can use
HttpContext.Current.Response.Write("Hello World");
There are sometimes issues with Response.Write but it should be okay for what you want to do here.
Use breakpoints. Set a breakpoint at the end of your method by clicking in the "gutter" area. A red circle will appear that looks like this:
Now run your program in debug mode by clicking the button with the green triangle or pressing F5. The program will run, producing the output in the console (a separate window). Once it hits your breakpoint, you can examine the console for the output, like this:
You are reading a tutorial for Console Application, however you are trying to create a ASP.NET application. I would reccomend reading a tutorial for ASP.NET
Like many before said: it goes by too fast, so either use breakpoints, or use a Read...
You can also write to your Visual Studio output window with System.Diagnostics.Debug.Write
you need to put break point over the line which you want to debug
short cut to placing break point is ctrl D,n
then you can step over or step into the code with f10 and f11 function keys
I am going to do some code in c# using visual studio 2010. The problem is that every time I run program it does appear in command prompt.
I would like place the output of the program in the console like in the Eclipse. System.Diagnostics.Debug.Write("abc"); this does not work cause if I look at the output I see much more information than I want. I would like to see only data which would show in the command prompt.
Check out "Tools->Options->Debug->Output Window" - you should be able to decrease amount of traces to your liking.
Side note: normally "output of program" means results of Console.WriteXXXX methods, so maybe you are looking for something completely different.
I think you wish to turn off verbose Output logging so that only your Debug.Write's will be written to the output window.
To do this you goto Tools > Options > Debugging > Output Window > and turn off the verbose logging:
If you want to keep all of your output, you can redirect your Debug.Print to output to the Immediate Window instead.
Tools -> Options -> Debugging -> General | Click on Redirect all Output Window text to the Immediate Window.
This does not mean everything will be outputted to it, just the output that you designate in your code and any exception messages that get thrown. It's a lot less chatty and still keeps your Output window with all the standard messages.