CSharp-LocalSonarAnalizer
1.0.2
See the version list below for details.
dotnet add package CSharp-LocalSonarAnalizer --version 1.0.2
NuGet\Install-Package CSharp-LocalSonarAnalizer -Version 1.0.2
<PackageReference Include="CSharp-LocalSonarAnalizer" Version="1.0.2" />
<PackageVersion Include="CSharp-LocalSonarAnalizer" Version="1.0.2" />
<PackageReference Include="CSharp-LocalSonarAnalizer" />
paket add CSharp-LocalSonarAnalizer --version 1.0.2
#r "nuget: CSharp-LocalSonarAnalizer, 1.0.2"
#:package CSharp-LocalSonarAnalizer@1.0.2
#addin nuget:?package=CSharp-LocalSonarAnalizer&version=1.0.2
#tool nuget:?package=CSharp-LocalSonarAnalizer&version=1.0.2
CSharp-LocalSonarAnalyzer
Advanced static code analyzer for C# that uses SonarAnalyzer.CSharp and SonarQube rules. Designed for local use in debug mode only.
Features
- Static code analysis using SonarQube rules
- Local debugging capabilities
- Code coverage reporting
- Build artifact cleanup for production deployments
Prerequisites
- .NET SDK (version X.X or higher)
- SonarAnalyzer.CSharp package
- Coverlet for code coverage (already configured)
Configuration
Code Coverage Setup
- Create a
coverlet.runsettings
file in yourApplication.Test
project - Add the following configuration:
<?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>
Production Deployment Cleanup (Optional)
To prevent generation of unnecessary BuildHost folders during deployment, add this to your startup project's .csproj file:
��� <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> ���
Usage
- Configure the coverlet.runsettings as shown above
- Build the solution in Debug mode
- Run the analyzer against your target project
- Review analysis results in your IDE or output window
Troubleshooting
- BuildHost folders still appearing: Ensure the Target is added to the correct project file and the Condition matches your release configuration
- Coverage not reported: Verify the runsettings file is in the correct location and includes match your project structure
Notes
- This analyzer is intended for local development use only
- For production analysis, consider using a full SonarQube server installation
- Remember to exclude test assemblies from coverage reports for accurate metrics
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 (>= 10.0.0-preview.4.25258.110)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.