Advanced static analyzer for C# code that uses the Roslyn framework (Microsoft.CodeAnalysis) to perform static code analysis. Designed specifically for local use in debug mode, allowing developers to perform code analysis and test coverage using the .NET BuildHost.
$ dotnet add package CodeAnalyzerGeneratorAn advanced static analyzer for C# code that uses the Roslyn framework (Microsoft.CodeAnalysis) to perform static code analysis. Designed specifically for local use in debug mode, allowing developers to perform code analysis and test coverage using .NET BuildHost.
// In Program.cs or Startup.cs
services.AddLocalSonarAnalizer(options =>
{
options.UseDebugConsole = true; // Enable the interactive console
});
The interactive console provides different types of messages with color codes:
The coverlet.runsettings file is required for coverage configuration. You have two options:
<?xml version="1.0" encoding="utf-8"?>
<RunSettings>
<DataCollectionRunSettings>
<DataCollectors>
<DataCollector friendlyName="XPlat code coverage">
<Configuration>
<Format>cobertura</Format>
<Include>
[Application]*CommandHandler*
[Application]*QueryHandler*
</Include>
<Exclude>
[xunit.*]*,
[Moq]*,
[FluentResults]*,
[SharedKernel]*,
[Domain]*,
[Web.Api]*,
[Infrastructure]*
</Exclude>
<ExcludeByAttribute>ExcludeFromCodeCoverage</ExcludeByAttribute>
<ExcludeByFile>
**/bin/**/*,
**/obj/**/*,
**/TestResults/**/*,
**/Models/**/*,
**/DependencyInjection.cs
</ExcludeByFile>
<IncludeTestAssembly>false</IncludeTestAssembly>
</Configuration>
</DataCollector>
</DataCollectors>
</DataCollectionRunSettings>
</RunSettings>
// Basic analysis
await analyzer.Analyze(solutionPath);
// Include test projects in the analysis
await analyzer.Analyze(solutionPath, analyzeRulesTestProjects: true);
// Complete analysis with coverage
await analyzer.Analyze(solutionPath, analyzeRulesTestProjects: true, runTestsAndCalculateCoverage: true);
// Complete analysis with HTML report
await analyzer.Analyze(solutionPath, analyzeRulesTestProjects: true, runTestsAndCalculateCoverage: true, outputHtml: true);
The tool generates two types of reports:
Analysis Report:
Coverage Report:
Problem: BuildHost folders continue to appear Solution:
Problem: Coverage report is not generated Solution:
If this package has been useful to you, please consider supporting its development:
This project is licensed under the terms of the MIT license.