简体   繁体   English

在命令行程序中使用自己的诊断程序

[英]Using own diagnostics in a command line program

I'm writing a command line program witch is intended to open a solution and scan the documents for errors and warnings. 我正在编写一个命令行程序,旨在打开解决方案并扫描文档以查找错误和警告。 I'm using the following code: 我正在使用以下代码:

private static async void testDocument(Document document)
{
    var syntaxTree = await document.GetSyntaxTreeAsync();
    var semanticModel = await document.GetSemanticModelAsync();

    var diagnostics = syntaxTree.GetDiagnostics().Concat(semanticModel.GetDiagnostics());
    foreach (var diagnostic in diagnostics)
    {
        Console.WriteLine(diagnostic.ToString());
    }
}

This works fine, but I also want to output warnings detected from diagnostics written by myself. 这工作正常,但我也想输出从我自己编写的诊断中检测到的警告。 These are located in another project created with the "Diagnostic with Code Fix" template. 它们位于使用“Diagnostic with Code Fix”模板创建的另一个项目中。 How can I put these two things together? 我怎么把这两件事放在一起?

When you create your Workspace , call the overload that takes a HostServices , and pass your own host that contains the default assebmlies as well as your own assemblies: 在创建Workspace ,调用带有HostServices重载 ,并传递包含默认的assebmlies以及您自己的程序集的主机

MSBuildWorkspace.Create(
    ImmutableDictionary<string, string>.Empty,
    MefHostServices.Create(
        MefHostServices.DefaultAssemblies.Add(Assembly.Load(...))
    )
);

One option is to use the Roslyn CSharp Compiler from Command Line. 一种选择是使用命令行中的Roslyn CSharp编译器。 You can pass the /analyzer switch with your own diagnostics dll. 您可以使用自己的诊断程序dll传递/analyzer开关。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用System.Diagnostics.Process在命令行上的文件中管道 - Piping in a file on the command-line using System.Diagnostics.Process 无法使用System.Diagnostics创建新的程序实例 - Can't create new program instance using System.Diagnostics 如何使用System.Diagnostics.Process运行命令? - How to run a command using System.Diagnostics.Process? 使用C#应用程序中的命令行程序 - Using a command line program from within a C# application 以管理员身份运行命令行程序 - Run a command line program as Administrator SyntaxNode.ContainsDiagnostics无法与您自己的诊断一起使用? - SyntaxNode.ContainsDiagnostics not working with your own diagnostics? 在我自己的程序中使用网络摄像头的按钮 - Using webcam's button in my own program 我正在使用 System.Diagnostics.Process 运行 sqlite 特殊命令,但只有一半的命令被执行 - I am using System.Diagnostics.Process to run the sqlite special command but only half of the commands get executed 使用命令提示符和System.Diagnostics.Process从asp.net页面重新启动Windows - Restart windows from asp.net page using command prompt and System.Diagnostics.Process 如何使用命令行编译WPF程序? - How to compile WPF program with command line?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM