0

I just have one question regarding C#.

I have downloaded Microsoft Visual C# 2010 Express to write the C# code.

Now, I want to compile the code using the same visual C#. Can I?

I have searched for a method to compile the code but all of the methods I founded are talking about command line 'cmd'. I tried using it but it gives me that "csc is not recognized as an internal or external command ....." although that the directory I was in is the same as the C# code directory

I want to compile and see the results in the output.

This is the original code to compile:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Project1
{
    class Example1_1
    {
        public static void Main()
        {
            // display “Hello World!” on the screen
            System.Console.WriteLine("Hello World!");
            // display the current date and time
            System.Console.WriteLine("The current date and time is " +
            System.DateTime.Now);
        }
    }
}

and the result of pressing F6 'build' is:

------ Build started: Project: Project1, Configuration: Release x86 ------
Project1 -> C:\Users\Ali Alnufaili\AppData\Local\Temporary Projects\Project1\bin\Release\Project1.exe ========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

If you have any suggestion, till me please. ^_^

sloth
  • 99,095
  • 21
  • 171
  • 219
Ali Essa
  • 29
  • 3
  • 6
  • 1
    Have you tried pressing F7 or Ctrl-B? Or even just going to the Build menu. Or am I missing something? – Nick May 16 '12 at 07:52
  • if you want to compile code in another app [it](http://stackoverflow.com/questions/7944036/compile-c-sharp-code-in-the-application) is your answer – ahmadali shafiee May 16 '12 at 07:54
  • Use the pre-configured shell: "`Visual Studio Command Prompt`". From there you can run the `msbuild` command on your solution file. If you want to do that automatically, just copy all the environment variables values from that shell into your script. – SK-logic May 16 '12 at 07:56

3 Answers3

2

Just press this button:

enter image description here

or hit F5 to compile and run your code.

EDIT:

So you are running a console application and write some text to the console. Maybe your problem is that the console window pops up and closes immediately?

Try adding System.Console.ReadKey(); at the bottom of your Main method. Then the console window will stay open until you hit a key.

Or go the directory where your compiled program is (looks like it is C:\Users\Ali Alnufaili\AppData\Local\Temporary Projects\Project1\bin\Release), open a command prompt (in windows explorer, hold down SHIFT and press the right mouse button and choose Open command prompt here), and run the executable in the command prompt (just type Project1.exe and hit enter)

sloth
  • 99,095
  • 21
  • 171
  • 219
  • Nice theme for VS. Which one is it? – George May 16 '12 at 08:37
  • @George http://www.nerdpad.com/visual-studio/visual-studio-2010-dark-expression-blend-color-theme – sloth May 16 '12 at 08:40
  • Thanks MR. dkson .. Although that it disappears very fast, I have tried to print-screen the console and I find the same result in the code. Thanks and I'll try to find the soulution you write to keep the console open. – Ali Essa May 16 '12 at 08:53
0

If you've created a project in Visual Studio, you should be able to simply use the "build" option from the menus/toolbars.

If you've got the default C# key bindings, I believe F6 is a shortcut to start under the debugger.

Rowland Shaw
  • 37,700
  • 14
  • 97
  • 166
  • I have added the code and the result of using F6 'Build'. I don't know why I can't see the outputs. I mean the "Hello World"! – Ali Essa May 16 '12 at 08:12
0

I'm sure you have used some tutorial for the example. Did the tutorial not mention pressing F5 to compile and run the application?

Your Build output says your program has compiled successfully, but to start your application, too, you need to press F5.

Also, currently your program will immediately exit when done. To make it wait, add the following line at the end:

Console.ReadLine();

That will let you see your output and then the program will wait until you press enter.

Botz3000
  • 39,020
  • 8
  • 103
  • 127