Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to compile just one file in c#?

Tags:

In VC++ I can press CTRL+F7 to compile a single file, or right click on a source file ot compile it. Is it possible to compile a single file (or current file) in C#?

I would like to for example know if my current file has any errors in it without having to compile everything.

like image 990
Winforms Avatar asked Jul 23 '10 17:07

Winforms


People also ask

How do I compile a file?

If you want to just compile a specific file, right click on its name on the left listing of files, and select Compile Current Document. Once the compile is completed, the results are displayed on the Compiler Output tab at the bottom of the screen.

Can you run a single C# file?

You can run a C# project or . csproj file if it's a runnable program. If the project contains a C# file with a Main method, and its output is an executable or .exe file, it will probably run if it builds successfully. If your program code is already in a Visual Studio project, open the project.

How C files are compiled?

Compilation process in C involves four steps: pre-processing, compiling, assembling, and linking. The preprocessor tool helps in comments removal, macros expansion, file inclusion, and conditional compilation. These commands are executed in the first step of the compilation process.


1 Answers

For single .cs file compile + run:

  1. In VS 2008, go to "Tools" > "External Tools"
  2. Click on "Add"
  3. Title: Run CSC (or whatever you want)
  4. Command: C:\Windows\system32\cmd.exe
  5. Arguments: /c C:\Windows\Microsoft.NET\Framework\v3.5\csc.exe /target:winexe $(ItemPath) && $(ItemFileName)
  6. Initial directory: $(ItemDir)
  7. Check Use Output Window
  8. Apply + Ok
  9. Go to Tools and choose "Run CSC"

If this doesn't work, verify that your paths for cmd and csc match.

like image 156
dicentiu Avatar answered Oct 03 '22 04:10

dicentiu