Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I compile and run c# program without using visual studio? [duplicate]

I am very new to C#. I have just run C# 'Hello World' program using Visual Studio.

Can I run or compile a C# program without using Visual Studio?

If it is possible, then which compiler should I use?

Thanks

like image 350
A.s. Bhullar Avatar asked Aug 17 '13 08:08

A.s. Bhullar


People also ask

How do I run a C program file?

Opening a file is performed using the fopen() function defined in the stdio. h header file. The syntax for opening a file in standard I/O is: ptr = fopen("fileopen","mode");

Do you need a compiler to run C?

C is a mid-level language and it needs a compiler to convert it into an executable code so that the program can be run on our machine.


2 Answers

If you have .NET v4 installed (so if you have a newer windows or if you apply the windows updates)

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc.exe somefile.cs 

or

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe nomefile.sln 

or

C:\Windows\Microsoft.NET\Framework\v4.0.30319\msbuild.exe nomefile.csproj 

It's highly probable that if you have .NET installed, the %FrameworkDir% variable is set, so:

%FrameworkDir%\v4.0.30319\csc.exe ...  %FrameworkDir%\v4.0.30319\msbuild.exe ... 
like image 50
xanatos Avatar answered Sep 26 '22 19:09

xanatos


I use a batch script to compile and run C#:

C:\Windows\Microsoft.NET\Framework\v4.0.30319\csc /out:%1 %2  @echo off  if errorlevel 1 (     pause     exit )  start %1 %1 

I call it like this:

C:\bin\csc.bat "C:\code\MyProgram.exe" "C:\code\MyProgram.cs" 

I also have a shortcut in Notepad++, which you can define by going to Run > Run...:

C:\bin\csc.bat "$(CURRENT_DIRECTORY)\$(NAME_PART).exe" "$(FULL_CURRENT_PATH)" 

I assigned this shortcut to my F5 key for maximum laziness.

like image 42
Big McLargeHuge Avatar answered Sep 22 '22 19:09

Big McLargeHuge