Hi community,
Recently Iβve added to my project .editorconfig file in order to ignore some of SonarCloud issues. I followed this advice
Here are my Azure DevOps tasks:
steps:
- task: SonarCloudPrepare@2
displayName: "Preparing SonarCloud Analysis"
inputs:
SonarCloud: "SonarCloud ---redacted---"
organization: " ---redacted---"
scannerMode: "MSBuild"
projectKey: "${{ parameters.sonarCloudProjectKey }}"
projectName: "${{ parameters.sonarCloudProjectName }}"
extraProperties: |
sonar.exclusions=**/obj/**, **/*.dll, **/Migrations/*.cs, ${{ parameters.sonarExclusions }}
sonar.cs.opencover.reportsPaths=$(Build.SourcesDirectory)/**/coverage.opencover.xml
sonar.cs.vstest.reportsPaths=$(Agent.TempDirectory)/*.trx
sonar.coverage.exclusions=${{ parameters.sonarCoverageExclusions }}
...some other tasks
- task: DotNetCoreCLI@2
displayName: "Build solution"
inputs:
command: "build"
arguments: "--no-restore"
configuration: $(buildConfiguration)
...some other tasks
- task: SonarCloudAnalyze@2
continueOnError: true
displayName: "Run SonarCloud analysis"
- task: SonarCloudPublish@2
continueOnError: true
displayName: "Publish SonarCloud analysis results on build summary"
And here is my .editorconfig file
[*.cs]
dotnet_diagnostic.S6966.severity = none
dotnet_diagnostic.S1144.severity = none
And here are some logs from the Azure DevOps pipeline that I can share. Theyβre coming from MS build step.
Starting: Build solution
==============================================================================
Task : .NET Core
Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
Version : 2.242.0
Author : Microsoft Corporation
Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
==============================================================================
Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
/home/devopsagentuser/vsts-agent-src-04/_work/_tool/dotnet/dotnet build -dl:CentralLogger,"/home/devopsagentuser/vsts-agent-src-04/_work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.242.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll"*ForwardingLogger,"/home/devopsagentuser/vsts-agent-src-04/_work/_tasks/DotNetCoreCLI_5541a522-603c-47ad-91fc-a4b1d163081b/2.242.0/dotnet-build-helpers/Microsoft.TeamFoundation.DistributedTask.MSBuild.Logger.dll" --no-restore
DOCOsoft.ExampleMicroservice.Infrastructure -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Infrastructure/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.Infrastructure.dll
Sonar: (DOCOsoft.ExampleMicroservice.Infrastructure.csproj) Project processed successfully
DOCOsoft.Tests.Shared.Conventions -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/src/DOCOsoft.Tests.Shared.Conventions/bin/Debug/net8.0/DOCOsoft.Tests.Shared.Conventions.dll
Sonar: (DOCOsoft.Tests.Shared.Conventions.csproj) Project processed successfully
DOCOsoft.ExampleMicroservice.BusinessLogic -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.BusinessLogic/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.BusinessLogic.dll
Sonar: (DOCOsoft.ExampleMicroservice.BusinessLogic.csproj) Project processed successfully
DOCOsoft.ExampleMicroservice.WebApp -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.WebApp/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.WebApp.dll
Sonar: (DOCOsoft.ExampleMicroservice.WebApp.csproj) Project processed successfully
##[warning]tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/BankDetailsEntity.cs(5,26): Warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144)
/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/BankDetailsEntity.cs(5,26): warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144) [/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/DOCOsoft.ExampleMicroservice.Domain.csproj]
##[warning]tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/AddressEntity.cs(10,26): Warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144)
/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/AddressEntity.cs(10,26): warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144) [/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/DOCOsoft.ExampleMicroservice.Domain.csproj]
##[warning]tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/UserEntity.cs(10,26): Warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144)
/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/UserEntity.cs(10,26): warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144) [/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/DOCOsoft.ExampleMicroservice.Domain.csproj]
DOCOsoft.ExampleMicroservice.Domain -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.Domain.dll
Sonar: (DOCOsoft.ExampleMicroservice.Domain.csproj) Project processed successfully
DOCOsoft.Tests.Shared.Fixtures -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/src/DOCOsoft.Tests.Shared.Fixtures/bin/Debug/net8.0/DOCOsoft.Tests.Shared.Fixtures.dll
Sonar: (DOCOsoft.Tests.Shared.Fixtures.csproj) Project processed successfully
##[warning]tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.DataAccess/DataContext.cs(12,43): Warning S1144: Remove the unused private setter 'set_Users'. (https://rules.sonarsource.com/csharp/RSPEC-1144)
/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.DataAccess/DataContext.cs(12,43): warning S1144: Remove the unused private setter 'set_Users'. (https://rules.sonarsource.com/csharp/RSPEC-1144) [/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.DataAccess/DOCOsoft.ExampleMicroservice.DataAccess.csproj]
DOCOsoft.ExampleMicroservice.DataAccess -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.DataAccess/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.DataAccess.dll
Sonar: (DOCOsoft.ExampleMicroservice.DataAccess.csproj) Project processed successfully
DOCOsoft.Tests.Shared.Fixtures.IntegrationTests -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/DOCOsoft.Tests.Shared.Fixtures.IntegrationTests/bin/Debug/net8.0/DOCOsoft.Tests.Shared.Fixtures.IntegrationTests.dll
Sonar: (DOCOsoft.Tests.Shared.Fixtures.IntegrationTests.csproj) Project processed successfully
DOCOsoft.ExampleMicroservice.DataAccess.UnitTests -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/tests/DOCOsoft.ExampleMicroservice.DataAccess.UnitTests/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.DataAccess.UnitTests.dll
Sonar: (DOCOsoft.ExampleMicroservice.DataAccess.UnitTests.csproj) Project processed successfully
DOCOsoft.ExampleMicroservice.BusinessLogic.UnitTests -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/tests/DOCOsoft.ExampleMicroservice.BusinessLogic.UnitTests/bin/Debug/net8.0/DOCOsoft.ExampleMicroservice.BusinessLogic.UnitTests.dll
Sonar: (DOCOsoft.ExampleMicroservice.BusinessLogic.UnitTests.csproj) Project processed successfully
DOCOsoft.Tests.Shared.UnitTests -> /home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/DOCOsoft.Tests.Shared.UnitTests/bin/Debug/net8.0/DOCOsoft.Tests.Shared.UnitTests.dll
Sonar: (DOCOsoft.Tests.Shared.UnitTests.csproj) Project processed successfully
Build succeeded.
/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/Entities/BankDetailsEntity.cs(5,26): warning S1144: Remove the unused private setter 'set_Id'. (https://rules.sonarsource.com/csharp/RSPEC-1144) [/home/devopsagentuser/vsts-agent-src-04/_work/319/s/tests/ExampleMicroservice/src/DOCOsoft.ExampleMicroservice.Domain/DOCOsoft.ExampleMicroservice.Domain.csproj]
Could you help me find out why rule no S6966 is ignored properly and S1144 is not?
Best regards,
Senior Software Engineer @ DOCOsoft
Augustyn Binkowski