创建 Visual Studio 2010 扩展以生成编译器警告
我想创建一个扩展来识别代码中的特定注释。我将使用 //@
注释前缀来表示代码异味。此扩展的一个功能是为编译代码时遇到的每个注释生成警告。可以这样做吗?
I want to create an extension to recognize specific comments in my code. I will use this to signal code smells by using the //@
comment prefix. One feature of this extension will be to generate warnings for each comment encountered while compiling the code. Is it possible to do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我不认为你可以连接编译器来生成警告。但是,“错误列表”视图聚合了来自多个源的错误、警告和消息。您只需将其添加到该列表中就足够了吗?
这是我可以找到的关于该主题的链接: http://www.mztools.com/articles /2008/MZ2008022.aspx
I don't think you can hook into the compiler to generate warning. However, the "Error List" view aggregates errors, warnings and messages from multiple sources. Would it be good enough for you to simply append to that list?
Here's a link I could find on the subject : http://www.mztools.com/articles/2008/MZ2008022.aspx
有一个名为 CodeSweep 的示例,它可以检测注释中的某些字符串(编写它是为了查找温和的脏话),并将任务添加到您的任务列表中。 http://code.msdn.microsoft.com/Code-Sweep-3bfb7bb5如果您无法按原样使用此代码,则阅读此代码可以帮助您编写自己的扩展。
您还可以使用现有的任务功能并添加自己的关键字(例如开箱即用的
//HACK
和//TODO
- 您可以添加//SMELL
) 速度更快,但控制力较差。 http://msdn.microsoft.com/en- us/library/zce12xx2(v=VS.100).aspx。这可能就是您所需要的。There is a sample called CodeSweep that detects certain strings in comments (it is written to look for mild swear words) that adds tasks to your Task List. http://code.msdn.microsoft.com/Code-Sweep-3bfb7bb5 Reading this code could help you write your own extension if you can't use it as-is.
You could also use the existing task functionality and add your own keywords (like the out-of-the-box
//HACK
and//TODO
- you could add//SMELL
) which is quicker but gives you less control. http://msdn.microsoft.com/en-us/library/zce12xx2(v=VS.100).aspx. This may be all you need.