When creating VB Roslyn compiler warning can be suppress using options:
options = options.WithSpecificDiagnosticOptions(
New Dictionary(Of String, ReportDiagnostic) From {
{“BC40000”, ReportDiagnostic.Suppress}, ’ Suppress BC40000 warning
{“BC42105”, ReportDiagnostic.Suppress}, ’ Suppress BC42105 warning
{“BC42005”, ReportDiagnostic.Suppress} ’ Suppress BC42005 warning
})
How can warning be suppress in the VBParser?
Thanks,
Rob
Hi Rob,
Here’s a code snippet that does the same job for the parser:
var vbParser = new VbParser(new MyVbSolution());
public class MyVbSolution : VbSolution
{
private IDictionary<string, ReportDiagnostic> diags;
public MyVbSolution()
{
diags = new Dictionary<string, ReportDiagnostic>
{
{ "BC40000", ReportDiagnostic.Suppress },
};
}
public override bool RegisterNamespaces(string[] nameSpaces, ProjectId projectId = null, string rootNamespace = null)
{
Project project = GetProjectOrDefault(projectId);
if (project == null)
return false;
ApplySolutionChanges(s => s.WithProjectCompilationOptions(
project.Id,
new VisualBasicCompilationOptions(
OutputKind.DynamicallyLinkedLibrary,
globalImports: GetGlobalImports(nameSpaces),
rootNamespace: rootNamespace,
parseOptions: GetParserOptions(projectId) as VisualBasicParseOptions).WithSpecificDiagnosticOptions(diags)));
Update();
return true;
}
protected override CompilationOptions GetCompilationOptions(ProjectId projectId)
{
return base.GetCompilationOptions(projectId).WithSpecificDiagnosticOptions(diags);
}
private IList<GlobalImport> GetGlobalImports(string[] namespaces)
{
if (namespaces == null || namespaces.Length == 0)
return null;
IList<GlobalImport> result = new List<GlobalImport>();
foreach (var import in namespaces)
{
result.Add(GlobalImport.Parse(import));
}
return result;
}
}
Overriding RegisterNamespaces should not be required, we will try to fix it in the next minor update.
Kind regards,
Dmitry
1 Like
Hi Dmitry,
I converted your code to VB.Net and I am getting the following error messages:
Here are the methods:

I have feeling it is because I am on version 9.5.15.
Rob
Fixed first error:

Fixed second error:

I’m assuming the newer version has overridden function passing “ProjectId”.
Rob
Hi Rob,
The code above would work for the latest version (10.0).
I’ve uploaded a VB project compatible with 9.5.15 here:
Please let me know if it works for you.
Kind regards,
Dmitry
1 Like