将自定义编译器与Visual Studio IDE集成 [英] Integrating a Custom Compiler with the Visual Studio IDE

查看:149
本文介绍了将自定义编译器与Visual Studio IDE集成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

背景:我想创建一个自定义VB编译器,扩展原始编译器,以处理我的自定义编译时属性。

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

问题:在我创建了我的自定义编译器后,我有一个能够通过标准命令行界面编译VB代码的可执行文件,如何将此编译器与Visual Studio IDE? (这样按编译或生成将使用我的编译器,而不是默认编译器)。

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 我如果我错了)

从这里的反应,我看到这个问题是有点令人震惊,所以我会进一步解释我的需要和背景:
.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属性装饰一个类。然后我们将类的一个实例传递给格式化程序的Serialize方法。

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.

现在,如果我们检查Synchronization,Flags,Obsolete和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.

当然,这些不是我个人的见解:书Applied .NET Attributes 提供了创建自定义属性和自定义C#编译器以在编译时反映该属性的完整示例(该示例用于实现java样式检查异常 )。

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

推荐答案

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.

这篇关于将自定义编译器与Visual Studio IDE集成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆