Sunday, January 23, 2011

Notepad++ with the C# compiler - you can do it

If you ever decided to to work a bit outside of Visual Studio and configure a plain text editor to work with the C# compiler, you most likely know that it's not so straightforward as it might seem. At first, I thought that it would be a relatively easy task to add a specific compiler reference to Notepad++, but it needed some additionalwork, as Notepad++ has no specific wizard or dialog to directly configure a custom compiler. However, there is a Run box (found in the Run menu) that can help you solve many problems:
There are two ways to use a compiler - either use the ... button and specify the path to the compiler, and then save it, or you could configure the PATH environment variable and use the compiler directly from the command line by calling the executable name.

I am going to start with the second option - set the specific PATH variable and then use csc (the C# compiler) from inside Notepad++. The reason behind this is that sometimes you will want to compile from the console (without an IDE or text editor) and this will make the task a lot easier. Not that you will encounter this scenario very often, but it is always a great plus to know how it can be automated - for example, you might want to have some compilation scripts later.
Before going any further, I tried to see how to set all correct PATH references so that I will make the system console .NET-enabled (excluding the option of running the Visual Studio Command Prompt bundled with the VS release you have). In the Program Files folder (or the host folder where you installed Visual Studio) there is the Visual Studio x.0 folder (replace x with the most recent version of Visual Studio installed on the machine). In the Common7 folder you will find the Tools folder and this is the final destination for now.

Read more: .NET Zone