CodeAnalyzerGenerator 1.0.0
dotnet add package CodeAnalyzerGenerator --version 1.0.0
NuGet\Install-Package CodeAnalyzerGenerator -Version 1.0.0
<PackageReference Include="CodeAnalyzerGenerator" Version="1.0.0" />
<PackageVersion Include="CodeAnalyzerGenerator" Version="1.0.0" />
<PackageReference Include="CodeAnalyzerGenerator" />
paket add CodeAnalyzerGenerator --version 1.0.0
#r "nuget: CodeAnalyzerGenerator, 1.0.0"
#:package CodeAnalyzerGenerator@1.0.0
#addin nuget:?package=CodeAnalyzerGenerator&version=1.0.0
#tool nuget:?package=CodeAnalyzerGenerator&version=1.0.0
CodeAnalyzerGenerator
Description
An 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.
Key Features
- โจ Static code analysis using Microsoft.CodeAnalysis (Roslyn)
- ๐ Code coverage report generation
- ๐จ Interactive console interface with color codes
- ๐ Reports in multiple formats (Console and HTML)
- ๐ Specific analysis coverage according to configuration
- ๐ Parallel execution for better performance
- ๐งน Cleanup of compilation artifacts
Prerequisites (optional)
- Coverlet (configured for code coverage)
Installation and Configuration
1. Project Configuration
// En Program.cs o Startup.cs
services.AddLocalSonarAnalizer(options =>
{
options.UseDebugConsole = true; // Enable the interactive console
});
2. Available Log Levels
The interactive console provides different types of messages with color codes:
- ๐ฆ Info (White): General information
- ๐ฉ Success (Green): Successful operations
- ๐จ Warning (Yellow): Warnings
- ๐ฅ Error (Dark Red): Errors
- ๐ด Critical (Red): Critical errors
- ๐ฆ Highlight (Cyan): Highlighted information
3. Code Coverage Configuration
The coverlet.runsettings
file is required for coverage configuration. You have two options:
- Automatic: If the file does not exist, it will be generated automatically at runtime.
- Manual: Create the file in your test project with this structure:
<?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>
4. Cleanup Configuration for Production (Optional)
To prevent unnecessary BuildHost folders from being generated during deployment:
<Target Name="DeleteBuildHostFoldersFromOutput" AfterTargets="AfterBuild" Condition="'$(Configuration)' == 'Release'">
<Message Text="[RELEASE POST-BUILD] Deleting BuildHost folders from Web.Api output: $(TargetDir)" Importance="high" />
<RemoveDir Directories="$(TargetDir)BuildHost-net472" />
<RemoveDir Directories="$(TargetDir)BuildHost-netcore" />
</Target>
Use
Public API
// 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);
Generated Reports
The tool generates two types of reports:
Analysis Report:
- Problems detected by the static analyzer
- Severity of problems (using Roslyn's DiagnosticSeverity)
- Exact location in the code
- Analysis time
Coverage Report:
- Coverage percentage per project
- Details of classes with incomplete coverage
- Uncovered lines
- Partially covered conditions
Troubleshooting
BuildHost Folders
Problem: BuildHost folders continue to appear Solution:
- Verify that the Target is in the correct .csproj file
- Confirm that the condition matches the release configuration
Coverage Not Reported
Problem: Coverage report is not generated Solution:
- Verify the existence of the runsettings file
- Check that the inclusion patterns match the project structure
- Verify that coverlet.collector is referenced in the test project
Important Notes
- ๐ Designed for local use in development
- ๐ ๏ธ Uses .NET BuildHost and Roslyn for static analysis
- ๐ Reports exclude test assemblies for accurate metrics
- โก Analysis runs in parallel using all available cores
- ๐จ Interactive console improves the development experience
License
This project is licensed under the terms of the MIT license.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 was computed. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net9.0
- Microsoft.Build.Locator (>= 1.9.1)
- Microsoft.CodeAnalysis.CSharp.Workspaces (>= 4.14.0)
- Microsoft.CodeAnalysis.Workspaces.MSBuild (>= 4.14.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 9.0.8)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last Updated |
---|---|---|
1.0.0 | 93 | 8/13/2025 |