4

我在 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

这可能是一个长镜头,但对我来说是值得的。我经常做这些事情。谢谢!

4

1 回答 1

2

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 现在应该运行您的自定义工具并在错误窗口中生成输出。

于 2010-03-14T10:42:33.493 回答