Compiling C# using the csc.exe compiler and Response Files

So, if like me you are used to pressing shift+F6 to build your current project you might some day also find it interesting to actually find out what that “build” actually does.

Below the hood the csc.exe compiler is busy at work, compiling all your code, using all the settings, files and references stipulated in your .csproj file.

If you open up a .csproj file in your favourite text editor EditPlus (it is, you’ve just not tried it yet!) you can fairly easily make sense of most of the XML and relate this to the underlying csc.exe operations.

You have things like “outputype” – so is this a webapp, a winform or just an exe file. Also you can set your “outputpath”.

Below all this you will see the referenced assemblies, and a list of all the code files to compile into your application.
Note that if you are a ASP.NET web developer and you are wondering why you can see all your .aspx.cs files and .aspx.designer.cs files – but not the .aspx files themselves – then you’ve missed an important gotcha about ASP.NET – .aspx files are dynamically compiled on the first request (for that page from the web application) into a class named [classname]_aspx – which of course inherits from your code behind. Along with the shadow-copy feature this is what allows you to update your .aspx files dynamically without redeploying or stopping your web-app (thou you should not do this on a live system).

So what could be more fun than trying to compile your application using the csc.exe tool instead of shift+F6?
A lot of things could is the answer, there is a good many reasons why we have IDEs – but still it is a slightly sobering or enlightening experience I guess to actually open up notepad, write a Program class with a Main method, save it and compile it using csc.exe and realise that you can actually write programs like this.

See here for a list of csc.exe parameters:

Finally note that Response files (.rsp) are much like a project files in that they define the files, options and references to be compiled by the csc.exe tool. These are also used by several build tools.


Leave a Reply

Please log in using one of these methods to post your comment: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

%d bloggers like this: