When I started Google about how to compile C# (.cs) file I found a lot of tutorial on that. Of course many of those article are correct I found some difficulty to run my single C# (.cs) file.
Why I need to compile separately:
Sometimes we found many tutorial or small code snippet on various desired topic, but to run that from Visual Studio we have to create Project and have to some unnecessary mouse click. So I tried to run the file directly from command prompt. Now lets dive into the process:
- Hope you must have installed Visual Studio in your computer.
- Open Windows command prompt.
- Go to the directory of Visual Studio bin folder. Example: C:\Program Files\Microsoft Visual Studio 10.0\VC\bin
- Then run the BATCH file >> vcvars32.bat Example: C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\vcvars32.bat. Now environment is set to run/compile your c sharp file.
- csc.exe this is the file that compile your .cs file and make the .exe file in the bin directory. your .cs file can be placed anywhere in your computer.
- Write csc following a space and then write your filename.cs and press enter. Example: C:\Program Files\Microsoft Visual Studio 10.0\VC\bin\csc filename.cs
- After compiling successfully the .exe file has been created in your bin folder.
- Now write the filename without .cs and it will run.
No comments:
Post a Comment