Friday, December 30, 2011

Exploring The C# Compiler's output in Visual Studio

Why am i so interested in the C# compiler? Good Question.

Well, one day i decided to get started with C#. I went on to build a C# HelloWorld Console Application using my newly obtained Visual Studio Environment.

To create such an application was very easy.

I opened up my Visual Studio Environment, selected the  File -> New -> Project option.


Visual Studio asked me what i wanted to create and in which .NET language, by showing me this dialog.

 

I chose, Visual C#, (on the left side of the screen, Project Types section) as my preferred .NET language and Console Application, as my application type (on the right side of the screen, Templates section).

And, hey presto, Visual Studio, created a new C# console application project for me. I said, that's good.

It also created a new Program.cs file (C# code files are named with .cs extension) and auto generated some code for me. I said that's cool.

My environment at this point of time looked like this.




Then i wrote a couple of lines of code like
             
            Console.WriteLine("Hello World!");
            Console.ReadKey();


, and chose Build Solution option from the Build menu.




There was a lot of activity going on in one of the screens of my environment. This is the Output Section.




I said, that's Fantastic!

I tried to look at the text from the output screen, and it said

------ Build started: Project: HelloWorld, Configuration: Debug Any CPU ------
C:\Windows\Microsoft.NET\Framework\v3.5\Csc.exe /noconfig /nowarn:1701,1702 /errorreport:prompt /warn:4 /define:DEBUG;TRACE /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Core.dll" /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Data.DataSetExtensions.dll" /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Data.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.dll /reference:C:\Windows\Microsoft.NET\Framework\v2.0.50727\System.Xml.dll /reference:"c:\Program Files\Reference Assemblies\Microsoft\Framework\v3.5\System.Xml.Linq.dll" /debug+ /debug:full /filealign:512 /optimize- /out:obj\Debug\HelloWorld.exe /target:exe Program.cs Properties\AssemblyInfo.cs

Compile complete -- 0 errors, 0 warnings
HelloWorld -> C:\Users\smarryboyina\Desktop\CSHARP\HelloWorld\HelloWorld\bin\Debug\HelloWorld.exe
========== Build: 1 succeeded or up-to-date, 0 failed, 0 skipped ==========

And then i said, Wow!

Looking at the text from the output section, i realized

a) Visual Studio was calling/invoking a program called Csc.exe, and it was placed under the path
     C:\Windows\Microsoft.NET\Framework\v3.5\

b) The Program code was being passed to this Csc.exe as a parameter.

c) There were some other switches and commands being used.

d) After this program executed, the results were shown to me.

e) Since my code was being sent to this Csc.exe program, and the returned results(Compile Complete), i assumed that this is the CSharp compiler.

f) I opened up my Windows Explorer, went to the path C:\Windows\Microsoft.NET\Framework\v3.5\, and examined the properties of the Csc.exe file, by rightclicking the file and selecting Properties.


and  the Description on the General tab told me that this was the C# Command line compiler. Thank you, Properties.

That was how my curiosity arose, and i decided to look at Csc.exe, The Visual C# Command Line Compiler.




No comments:

Post a Comment