visual-studio-2008 – 自定义输出=> VS2008 IDE中的错误解释列表

我在VS2008中有一个“数据库解决方案”项目 – 它从某种模板为多个数据库供应商生成SQL.为了节省时间,我还在VS2008中配置了一个工具(
Python脚本),它可以编译单个存储过程.现在,使用Python脚本,我可以自由地处理输出并使其具有我想要的任何形式.我正在想着让这些错误和警告以某种方式识别并填充可点击的错误/警告列表.这就是典型的Oracle错误:

LINE/COL ERROR
-------- -----------------------------------------------------------------
324/5    PL/SQL: Statement ignored
324/82   PLS-00363: expression 'VSOURCE_SYSTEM_ID' cannot be used as an
     assignment target
Warning: Procedure created with compilation errors.
PROCEDURE: ADD_PROPOSED error on creation
Errors for PROCEDURE ADD_PROPOSED:
LINE/COL ERROR

这可能是一个长镜头,但对我来说是值得的.我做了很多这样的事情.谢谢!

最佳答案
IVsSingleFileGenerator接口有一个方法调用
void Generate(…),其参数类型为
IVsGeneratorProgress.此接口有一个方法void
GeneratorError(),它允许您向Visual Studio错误列表报告错误和警告. GenerateError()在其他参数中包含一行和一列,因此我假设双击您的自定义错误会将您带到源文件中的适当位置.

为了把它们全部拉到一起,我会做类似以下的事情:

public class MyGenerator : IVsSingleFileGenerator
{
   public Generate(string path, string inputContents, string namespace, IntPtr[] outputContents, out unit outputLength, IVsGeneratorProgress progress)
   {
      // Invoke your Python script

      // Parse the error output from either a file or structure
      // Assume you generate two lists: one for warnings, one for errors

      foreach (var error in PythonErrors)
        progress.GenerateError(false, 0, error.Text, error.Line, error.Column);

      foreach (var warning in PythonErrors)
         progress.GenerateError(true, 0, warning.Text, warning.Line, warning.Colum);
   }
}

将其编译为程序集. (我不清楚这是否应该是一个EXE或DLL,但我怀疑是否会有效,因为你有一个实现正确接口的类.)然后转到项目中每个SQL文件的属性并关联MyGenerator用它的自定义工具.编译项目时,Visual Studio现在应该运行自定义工具并在错误窗口中生成输出.

点赞