Template for a good new topic, formatted with Markdown:
ALM used : Azure DevOps
CI system used: Azure DevOps
Scanner command used when applicable (private details masked):
Run code Analysis step in CI and this succeeds, then checking the pullrequest Status/Code in Sonarcloud -> it shows no errors!
First of all, if you analyze the project locally with our analyzers, will the issue show up?
For the Prepare step , can you add the sonar.verbose property set to true? And then upload here the logs from the Prepare Step, Build and also from the “Run Code Analysis” step?
I put in the verbose. I see in the Build Step following errors:
Warning CS8032: An instance of analyzer SonarAnalyzer.Rules.CSharp.ThreadStaticWithInitializer cannot be created from C:\Users\VssAdministrator\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
2020-08-25T12:52:13.1073706Z CSC : warning CS8032: An instance of analyzer SonarAnalyzer.Rules.CSharp.ThreadStaticWithInitializer cannot be created from C:\Users\VssAdministrator\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified.. [D:\a\1\s\FlidsApi\FlidsApi.csproj]
2020-08-25T12:52:13.1080419Z ##[warning]CSC(0,0): Warning CS8032: An instance of analyzer SonarAnalyzer.Rules.CSharp.MutableFieldsShouldNotBePublicReadonly cannot be created from C:\Users\VssAdministrator\AppData\Local\Temp\.sonarqube\resources\0\SonarAnalyzer.CSharp.dll : Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.3.1.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The system cannot find the file specified..
I will look into this because i think this might have something to do with it?
It’s really frustrating. I can’t get it to work.
Still getting same error in the Build: Could not load file or assembly 'Microsoft.CodeAnalysis, Version=1.3.1.0
Have tried just about everything that i googled but nothing works.
Hope you might have a solution…
I’m running a VS2019 solution on a windows-2019 azure agent with the Microsoft.CodeAnalysis, Version=1.3.1.0 added to all 4 projects.
I have an update for you. I have managed to not get the ‘Could not load Microsoft.CodeAnalysis’ anymore by running the agent on a local machine. But!
Sonarcloud is still not breaking on my code:
I see in your “run analysis” logs that your class to test is in FlidsApi\Helpers\SonarcloudQualityGateTest.cs , however I don’t see it in the MSBuild logs. Is the FlidsApi scanned at all?
For example, it’s clear that our analyzer is running , in the MSBuild logs you can see warnings like:
2020-08-26T09:05:21.4727724Z ##[warning]FlidsApi.Core\Helpers\EnumMappingHelper.cs(7,1): Warning S1128: Remove this unnecessary 'using'.
2020-08-26T09:05:21.4732995Z Helpers\EnumMappingHelper.cs(7,1): warning S1128: Remove this unnecessary 'using'. [D:\a\1\s\FlidsApi.Core\FlidsApi.Core.csproj]
We need to look at the diagnostics logs of the msbuild command. Please run the build with the /v:diag parameter (see verbosity in MSBuild command-line reference).
I added the /v:diag to the build and get loads of information.
I see following error: \Local\Temp.sonarqube\resources\3\SonarAnalyzer.CSharp.dll does not contain any analyzers
Maybe this is the cause for not validating the code?
I put in critical code, so it should break:
Most likely you ran the BEGIN step twice without running the END step which does some cleanup. There analyzers are downloaded by the scanner for msbuild and stored in %TEMP%/.sonarqube\resources. From the error message, it seems the folder is in a corrupted state.