集成自定义编译器与Visual Studio IDE编译器、自定义、Visual、Studio

2023-09-04 02:06:24 作者:似命般的宣泄

背景:我想创建一个自定义的VB编译器,延长了原生态的编译器,来处理我的自定义编译时属性

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

问题:我已经创建了我的自定义编译器和我有能力通过标准的命令行界面编写VB code的可执行文件后,如何整合这个编译器在Visual Studio IDE? (这样pressing编译或构建会利用我的编译器而不是默认的编译器)。

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)

在这里的反应,我看这个问题有点令人震惊,因此我将进一步解释我的需求和背景: .NET为我们提供了所谓的属性有很大机制。据我了解,使得属性的属性元素(组件,模块,类,方法等),在运用他们的预期的行为 - 属性,必须在得到体现。因此,这里真正的诀窍是体现和运用行为,在正确的位置。

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.

让我们序列化,例如:我们的装饰类用Serializable属性。然后,我们通过类的实例来格式化的序列化方法。格式化反映了情况后,检查是否有Seri​​alizable属性,并采取相应的行动。

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.

现在,如果我们考察同步,标志,过时和CLSCompliant属性,那么真正的问题是:谁体现在他们身上?至少在某些情况下,它必须是编译器(和/或IDE)。因此,看来,如果我想创建不管改变任何特定的消费的一个元素的行为自定义属性,我必须扩展编译器,以反映在他们的汇编。

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.

当然,这些都不是我个人的见解:这本书应用.NET属性提供了一个完整的例如,创建一个自定义属性和自定义的C#编译器的反思,在编译的属性(这个例子是用来实现Java风格的checked异常)。

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").

推荐答案

退房的MSBuild概述在的 http://msdn.microsoft.com/en-us/library/ms171452.aspx 。 Visual Studio项目都是MSBuild的项目。我相信你必须做的是做一些小的改动。我没有做它的编译器,但我编译后,做到了与ILMerge和它的伟大工程。无缝,甚至可以调试合并后的组件。

Check out "MSBuild Overview" at http://msdn.microsoft.com/en-us/library/ms171452.aspx. Visual Studio projects are MSBuild projects. I believe all you would have to do is make a couple minor changes. I have not done it for a compiler, but I did it with ILMerge after compiling and it works great. Seamless and even possible to debug the merged assemblies.