This article describes how to compile C # And il code and use the "vs2012 developer command prompt" to compile the code into an assembly and run the program.
□C # compile the file as an assembly
→ Create an as folder on drive F
→ Create myclass. Cs in the as folder
→ Open and write the following code in notepad and save
using System;
public class MyClass
{
public static void PrintSth()
{
Console.WriteLine("Hello");
}
}
→ Open "vs2012 developer command prompt", enter the following command, and press ENTER
→ Run the following command to compile myclass. cs into the myclass. dll Assembly file, and press ENTER
View the as folder under drive F. An additional myclass. dll assembly is added.
□Il file compiled into assembly
→ Create secondclass. Il in the as folder
→ Open and write the following code in notepad and save
.assembly SecondClassAssembly {}
.assembly extern mscorlib {}
.class public SecondClass extends [mscorlib]system.object{
.method public static void PrintSth() cil managed{
ldstr "hello from IL"
call void [mscorlib]System.Console::WriteLine(string)
ret
}
}
→ Enter the following command:
→ Press enter to see the following page:
In the as folder under drive F, a secondclassassembly. dll assembly is added.
→ View the DLL file in the as folder, enter the following command, and press ENTER
□Use the Assembly to run the program
→ Create mainclass. Cs in the as folder
→ Open and write the following code in notepad and save
using System;
class MainClass
{
static void Main()
{
MyClass.PrintSth();
}
}
→ Open "vs2012 developer command prompt", enter the following command, and press ENTER
In the asfile folder under the fdisk, A mainclass.exe assembly is added.
→ Enter the following command and press Enter.
C # Assembly series 01, use NotePad to write C # And il code, use the DOS command to compile the assembly, and run the program