[英]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.