Search code examples
c#classcmdcommand-linecompilation

How to compile a single C# class file to .exe using the command-line?


I am having trouble trying to compile a single class file to a executable. This is just a .cs file on its own with a simple hello world like so

using System;
using System.Diagnostics;
using System.Linq;
using System.Linq;


namespace Q3J1G0HFP7EXE58
{
    class Program
    {


        static void Main(string[] args)
        {
            Console.Title = "First Attempt";
            Console.WriteLine("Hello World!");
            Console.ReadKey();
        }
    }
}

How would I, from the command line compile this into a .exe file? Or what process would I need to do in order to get it into a .exe file (all from command like pref). 3rd party programs are a welcome suggestion, I have tried using the csc method but it will not work with just a class file.

It's going to be auto generated code which I then want to compile as a separate program from the one which wrote the code to file. Writing to executable is suppose to be a completely automated process but compiling is becoming an issue.


Solution

  • Apparently I was just being blind, I got it to work.

    C:\WINDOWS\Microsoft.NET\Framework64\v4.0.30319\csc.exe -out:dir\test.exe dir\Test.cs