/*
Author: Jiangong SUN
*/
CSharp compiler is invoked at the command line using csc.exe file located <C:\Windows\Microsoft.NET\Framework\v2.0.50727>.
CSharp Compiler compiles CSharp code to MSIL(Intermediate Language) at compilation time in CLR (Common Language Runtime). The compiled code(exe or dll) is managed code, and is managed by Garbage Collector(GC).
When you execute the exe or dll file, it will be compiled by JIT(Just-In-Time) compiler, and generate native machine code for specific CPU.
When you want to compile a class using csc.exe you may encounter this error:CS 1619: Cannot create temporary file
All you need to do is run cmd.exe as "Administrator". Re-run the compiler and it will compile the csharp file to an executable(.exe).
Compile csharp code to DLL (dynamic link library).
Note: .exe and .dll are all assembly files.
Compile CSharp code to named executable file.
Compile all the .CS files in current directory with a name of executable, the code mode can be DEBUG or RELEASE with optimization.
It will generate code in mode "DEBUG" like:
#if DEBUG
LazySingleton s2 = LazySingleton.Instance;
int num2 = s2.MultiplyBy5(20);
Console.WriteLine(num2);
#endif
Compile all the .CS files in current directory to a named DLL file "/target:library /out:LazyDLL.dll", and generate debug file(.pdb) with option "/debug", and doesn't display Microsoft copyright with option "/nologo", with warning level (0-4) "/warn:0".
Compile all the .CS file in current directory to a user personalized type of DLL.
Compile a class inside a .CS file who reference another class in another .CS file.
For example:
To compile <ConsoleApplication.cs>, you need to reference <ConsoleClass.cs> before it.
I hope this post can do help in your work. Enjoy coding!
本文介绍了如何在命令行中使用csc.exe编译C#代码,讲解了C#编译器将源代码编译为MSIL并由.NET运行时管理的过程。讨论了JIT编译、编译错误CS1619的解决方法,以及如何编译为exe、dll文件,包括设置调试模式、生成DLL和引用不同源文件的方法。

409

被折叠的 条评论
为什么被折叠?



