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. 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:
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. You can pass the /analyzer
switch with your own diagnostics dll.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.