CSharp-LocalSonarAnalizer
1.0.3
dotnet add package CSharp-LocalSonarAnalizer --version 1.0.3
NuGet\Install-Package CSharp-LocalSonarAnalizer -Version 1.0.3
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="CSharp-LocalSonarAnalizer" Version="1.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="CSharp-LocalSonarAnalizer" Version="1.0.3" />
<PackageReference Include="CSharp-LocalSonarAnalizer" />
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add CSharp-LocalSonarAnalizer --version 1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: CSharp-LocalSonarAnalizer, 1.0.3"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package CSharp-LocalSonarAnalizer@1.0.3
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=CSharp-LocalSonarAnalizer&version=1.0.3
#tool nuget:?package=CSharp-LocalSonarAnalizer&version=1.0.3
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
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>
- In your application, you must install the Nuget package https://www.nuget.org/packages/Microsoft.CodeAnalysis.Workspaces.MSBuild/
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. |
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
-
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.