Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling C# code from the command line gives error

Tags:

I am following this tutorial:

http://www.csharp-station.com/Tutorials/Lesson01.aspx

I pasted this into a text file, named it Welcome.cs:

// Namespace Declaration using System;  // Program start class class WelcomeCSS {     // Main begins program execution.     static void Main()     {         // Write to console         Console.WriteLine("Welcome to the C# Station Tutorial!");      } } 

Then I went into the command prompt, and pointed to the file's directory. I typed csc.exe Welcome.cs and got this error message:

csc.exe is not recognized as internal or external command 

I am using Visual Studio 2008

I tried moving csc.exe to the Windows directory, and now I am getting this error:

fatal error cs2018: unable to find messages file 'cscompui.dll' 

How can I compile my C# code from the command line?

like image 244
Alex Gordon Avatar asked Aug 06 '10 15:08

Alex Gordon


1 Answers

csc.exe isn't in your path. Try fully-qualifying it:

C:\WINDOWS\Microsoft.NET\Framework\v3.5\csc.exe 

(replace 3.5 with whatever framework you're using, of course.)

Note that Visual Studio isn't being used here. Doesn't matter what version of that you're using, because you're not using it when you compile from the command line. The command line compiler is part of the framework itself.

like image 174
David Avatar answered Oct 05 '22 13:10

David