Using your own diagnostics on the command line

I am writing a command line program that is designed to open a solution and check documents for errors and warnings. I am 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 great, but I also want to output the warnings I found in the diagnostics I wrote. They are located in another project created with the Diagnostics and Code Fix template. How can I combine these two things?

+3


source to share


2 answers


On build, Workspace

call the overload that accepts HostServices

and pass your own host containing the default assebmlies as well as your own assemblies:



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

      

+1


source


One option is to use the Roslyn CSharp compiler from the command line. You can pass the switch /analyzer

using your own diagnostic DLL.



0


source







All Articles