I am learning concepts related to .NET framework. I am confused at one point. From what I understand the compilers CSC.exe and AL.exe compiles the files to form assembly based on the switches. So my question is 1) Different compilers in .NET framework targets the CLR. So does this mean tha开发者_如何学Got individual files(code) and resource files are compiled to form an assembly and this assembly is executed at runtime by the CLR?
2) How does this happen when I use Visual Studio .NET?
Thanks.
Yes, that is correct. The assembly contains the MSIL translation of the source files, which the CLR converts into machine code and executes.
When you choose the Build command in Visual Studio, it runs the compiler appropriate to the kind of files in your project (e.g. the C# compiler for C# source files), and produces an assembly. (VS doesn't actually execute csc.exe, al.exe, etc.; it uses in-process equivalents. But the upshot is essentially the same.)
The answer to question 1 is: Yes.
The answer to question 2 is the Visual Studio invokes the compiler for you and uses your project file to provide the compiler with the information it needs to create the assembly.
1: pretty much; note that all the files must be considered together (they aren't generally compiled individually and then combined), and that technically IL isn't "executed" (since it isn't native CPU instructions); it must be either translated (by the JIT or NGEN) into machine code, or on some platforms ("micro framework") it is interpreted. But the result is the same...
2: same process, except it doesn't call the exes directly - it just invokes the code directly.
The concept of a namespace is not related to that of an assembly. A single assembly may contain types whose hierarchical names have different namespace
roots, and a logical namespace root may span multiple assemblies. In the .NET Framework, a namespace is a logical design-time naming convenience, whereas an assembly establishes
the name scope for types at run time.
Shrirang Jadhav
精彩评论