Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Integrating a Custom Compiler with the Visual Studio IDE

Background: I want to create a custom VB compiler, extending the "original" compiler, to handle my custom compile-time attributes.

Question: after I've created my custom compiler and I've got an executable file capable of compiling VB code via the standard command-line interface, how do I integrate this compiler with the Visual Studio IDE? (such that pressing "compile" or "build" will make use of my compiler instead of the default compiler).

EDIT: (Correct me if i'm wrong)

From the reactions here, I see this question is a bit shocking, so I shall further explain my needs and background: .NET provides us with a great mechanism called Attributes. As far as I understand, making attributes apply their intended behavior upon the attributed element (assembly, module, class, method, etc.) - attributes must be reflected upon. So the real trick here is reflecting and applying behavior at the right spot.

Lets take Serialization for example: We decorate a class with the Serializable attribute. We then pass an instance of the class to the formatter's Serialize method. The formatter reflects upon the instance, checking if it has the Serializable attribute, and acting accordingly.

Now, if we examine the Synchronization, Flags, Obsolete and CLSCompliant attributes, then the real question is: who reflects upon them? At least in some cases, it has to be the compiler (and/or IDE). Therefore, it seems that if I wish to create custom attributes that change an element's behavior regardless of any specific consumer, i must extend the compiler to reflect upon them at compilation.

Of course, these are not my personal insights: the book "Applied .NET Attributes" provides a complete example of creating a custom attribute and a custom C# compiler to reflect upon that attribute at compilation (the example is used to implement "java-style checked exceptions").

like image 605
M.A. Hanin Avatar asked Apr 13 '10 10:04

M.A. Hanin


1 Answers

Check out "BuildAction Property" and "CustomTool Property".

A few years ago, I read an excellent article about creating a custom compiler, registering it, and setting these properties. I cannot find the article now, but this should get you started.

like image 174
AMissico Avatar answered Oct 05 '22 23:10

AMissico