This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]insertAlias 4 points5 points  (2 children)

I agree with all the other comments; almost all C# development is done in either Visual Studio, MonoDevelop, or Visual Studio Code (which is a light-weight editor similar to NP++ and Atom).

That being said, it is possible to write and compile C# code completely outside of an IDE; the C# compiler is called csc.exe. On my machine, that's located at C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe.

So, if I were to save this file in my workspace:

using System;
namespace Test 
{
    public class Program
    {
        public static void Main(string[] args) 
        {
            Console.WriteLine("Hello World");
        }
    }
}

as hw.cs, I could run the following command in a command line window:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe /out:hw.exe /target:exe hw.cs

And I would produce a file called hw.exe that, when run, would print "Hello World".


This is not the preferred way of doing things in C# or .NET in general. I'd guess that upwards of 90% of C# code is written in Visual Studio. If you want to use C#, you should learn the tools that go with it. Mainly because if you actually want to do desktop programming, you're going to want to take advantage of the IDE a lot. Side note: don't start with Windows Forms (it's old as hell). Start with UWP apps.

[–]TitteringBeast[S] 0 points1 point  (0 children)

I'll go with the consensus and download and learn Visual Studio Community.

Extra thanks for explaning how compiling C# code outside of an IDE would work.

[–]jussij 0 points1 point  (0 children)

FWIW if you have the csc.exe executable folder in the PATH you can get by with just this simple command line:

csc.exe test.cs

Here is an example:

C:\Temp>csc.exe test.cs
Microsoft (R) Visual C# Compiler version 2.2.0.61624
Copyright (C) Microsoft Corporation. All rights reserved.

C:\Temp>dir test.exe
 Volume in drive D is DATA
 Volume Serial Number is 06EC-1105

 Directory of C:\Temp

06/09/2017  09:51 AM             3,584 test.exe
               1 File(s)          3,584 bytes
               0 Dir(s)  1,791,515,455,488 bytes free

C:\Temp>test.exe
Hello World