Analysis Csharp

Hello friends

I am analyzing a code in dotnet, but the sonar does not identify the Csharp, only the secondary link appears, what can I do?

Hi Pablo,

How do you analyze your project? To analyze C# code you need to use Scanner for MSBuild. It will automatically analyze non-.NET languages (e.g. JavaScript, CSS, etc.) only if the corresponding files are included in a C# or VB.NET project.

If the other language files are not included in a project, they will not be analyzed by Scanner for MSBuild. If you execute a second analysis using the Scanner CLI (e.g. the usual way to analyze non-.NET languages) on the same folder with the same SonarQube project key, it will overwrite (e.g. delete) the results from the C# analysis. In such cases we usually recommend creating a second SonarQube project for the non-.NET languages.

Kind regards,
Valeri

Thanks for the feedback.

I have used the following msbuild parameters

Below is the one that was executed

C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master>SonarScanner.MSBuild.exe begin /k:“CSharp”
SonarScanner for MSBuild 4.4.1
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at C:\sonar.msbuild\SonarQube.Analysis.xml
Loading analysis properties from C:\sonar.msbuild\SonarQube.Analysis.xml
Pre-processing started.
Preparing working directories…
12:04:47.623 Updating build integration targets…
12:04:47.67 Fetching analysis configuration settings…
12:04:48.071 Provisioning analyzer assemblies for cs…
12:04:48.071 Installing required Roslyn analyzers…
12:04:48.277 Provisioning analyzer assemblies for vbnet…
12:04:48.277 Installing required Roslyn analyzers…
12:04:48.308 Pre-processing succeeded.

C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master>MSBuild.exe <websocket-sharp.sln> /t:Rebuild

C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master>SonarScanner.MSBuild.exe end
SonarScanner for MSBuild 4.4.1
Using the .NET Framework version of the Scanner for MSBuild
Default properties file was found at C:\sonar.msbuild\SonarQube.Analysis.xml
Loading analysis properties from C:\sonar.msbuild\SonarQube.Analysis.xml
Post-processing started.
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\websocket-sharp\bin\Debug\websocket-sharp.dll.RoslynCA_fixed.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\Example2\bin\Debug\example2.exe.RoslynCA_fixed.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\Example3\bin\Debug\example3.exe.RoslynCA_fixed.json
Fixed invalid Code Analysis ErrorLog file. Please check that VS 2015 Update 1 (or later) is installed. Fixed file: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\Example\bin\Debug\example.exe.RoslynCA_fixed.json
SONAR_SCANNER_OPTS is not configured. Setting it to the default value of -Xmx1024m
Calling the SonarQube Scanner…
INFO: Scanner configuration file: C:\sonar.msbuild\sonar-scanner-3.2.0.1227\bin…\conf\sonar-scanner.properties
INFO: Project root configuration file: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out\sonar-project.properties
INFO: SonarQube Scanner 3.2.0.1227
INFO: Java 1.8.0_191 Oracle Corporation (64-bit)
INFO: Windows 10 10.0 amd64
INFO: SONAR_SCANNER_OPTS=-Xmx1024m
INFO: User cache: C:\Users\pablo.almeida.nalbatech.sonar\cache
INFO: SonarQube server 7.4.0
INFO: Default locale: “pt_BR”, source code encoding: “windows-1252” (analysis is platform dependent)
INFO: Publish mode
INFO: Load global settings
INFO: Load global settings (done) | time=85ms
INFO: Server id: BF41A1F2-AWcdBphD81RTrz5udaY9
INFO: User cache: C:\Users\pablo.almeida.nalbatech.sonar\cache
INFO: Load/download plugins
INFO: Load plugins index
INFO: Load plugins index (done) | time=47ms
INFO: Load/download plugins (done) | time=85ms
INFO: Loaded core extensions:
INFO: Process project properties
INFO: Load project repositories
INFO: Load project repositories (done) | time=38ms
INFO: Load quality profiles
INFO: Load quality profiles (done) | time=47ms
INFO: Load active rules
INFO: Load active rules (done) | time=1103ms
INFO: Load metrics repository
INFO: Load metrics repository (done) | time=31ms
INFO: Project key: CSharp
INFO: Project base dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master
INFO: ------------- Scan Example
INFO: Base dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\Example
INFO: Working dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out.sonar\CSharp_CSharp_52805AEC-EFB1-4F42-BB8E-3ED4E692C568
INFO: Source paths: Program.cs, AssemblyInfo.cs, Notifier.cs, NotificationMessage.cs
INFO: Source encoding: UTF-8, default locale: pt_BR
INFO: Load server rules
INFO: Load server rules (done) | time=332ms
INFO: Index files
INFO: 4 files indexed
INFO: Quality profile for cs: Sonar way
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor C# Properties [csharp]
WARNING: WARN: Analyzer working directory does not exist: ‘C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out\4\output-cs’. Analyzer results won’t be loaded from this directory.
INFO: Sensor C# Properties [csharp] (done) | time=16ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
INFO: SCM Publisher is disabled
INFO: ------------- Scan Example3
INFO: Base dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\Example3
INFO: Working dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out.sonar\CSharp_CSharp_C648BA25-77E5-4A40-A97F-D0AA37B9FB26
INFO: Source paths: AssemblyInfo.cs, Program.cs, Chat.cs, Echo.cs, App.config, Public/index.html, Public/Js/echotest.js
INFO: Source encoding: UTF-8, default locale: pt_BR
INFO: Index files
INFO: 7 files indexed
INFO: Quality profile for cs: Sonar way
INFO: Quality profile for js: Sonar way
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=7ms
INFO: Sensor SonarJS [javascript]
INFO: 1 source files to be analyzed
INFO: Sensor SonarJS [javascript] (done) | time=263ms
INFO: 1/1 source files have been analyzed
INFO: Sensor ESLint-based SonarJS [javascript]
INFO: Using default Node.js executable: ‘node’.
INFO: Sensor ESLint-based SonarJS [javascript] (done) | time=72366ms
ERROR: Failure during analysis, Node.js command to start eslint-bridge server was not built yet.
org.sonarsource.nodejs.NodeCommandException: Error when starting the process: node -v
at org.sonarsource.nodejs.NodeCommand.start(NodeCommand.java:75)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.getVersion(NodeCommandBuilderImpl.java:172)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.checkNodeCompatibility(NodeCommandBuilderImpl.java:145)
at org.sonarsource.nodejs.NodeCommandBuilderImpl.build(NodeCommandBuilderImpl.java:121)
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
INFO: SCM Publisher is disabled
INFO: ------------- Scan websocket-sharp
at org.sonar.plugins.javascript.eslint.EslintBridgeServerImpl.startServer(EslintBridgeServerImpl.java:114)
at org.sonar.plugins.javascript.eslint.EslintBasedRulesSensor.execute(EslintBasedRulesSensor.java:81)
at org.sonar.scanner.sensor.SensorWrapper.analyse(SensorWrapper.java:45)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:88)
at org.sonar.scanner.phases.SensorsExecutor.execute(SensorsExecutor.java:62)
at org.sonar.scanner.phases.AbstractPhaseExecutor.execute(AbstractPhaseExecutor.java:74)
at org.sonar.scanner.scan.ModuleScanContainer.doAfterStart(ModuleScanContainer.java:164)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.scan.ProjectScanContainer.scan(ProjectScanContainer.java:319)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:314)
at org.sonar.scanner.scan.ProjectScanContainer.scanRecursively(ProjectScanContainer.java:312)
at org.sonar.scanner.scan.ProjectScanContainer.doAfterStart(ProjectScanContainer.java:288)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.task.ScanTask.execute(ScanTask.java:48)
at org.sonar.scanner.task.TaskContainer.doAfterStart(TaskContainer.java:82)
at org.sonar.core.platform.ComponentContainer.startComponents(ComponentContainer.java:136)
at org.sonar.core.platform.ComponentContainer.execute(ComponentContainer.java:122)
at org.sonar.scanner.bootstrap.GlobalContainer.executeTask(GlobalContainer.java:131)
at org.sonar.batch.bootstrapper.Batch.doExecuteTask(Batch.java:116)
at org.sonar.batch.bootstrapper.Batch.execute(Batch.java:71)
at org.sonarsource.scanner.api.internal.batch.BatchIsolatedLauncher.execute(BatchIsolatedLauncher.java:46)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.sonarsource.scanner.api.internal.IsolatedLauncherProxy.invoke(IsolatedLauncherProxy.java:60)
at com.sun.proxy.$Proxy0.execute(Unknown Source)
at org.sonarsource.scanner.api.EmbeddedScanner.doExecute(EmbeddedScanner.java:171)
at org.sonarsource.scanner.api.EmbeddedScanner.execute(EmbeddedScanner.java:128)
at org.sonarsource.scanner.cli.Main.execute(Main.java:111)
at org.sonarsource.scanner.cli.Main.execute(Main.java:75)
at org.sonarsource.scanner.cli.Main.main(Main.java:61)
Caused by: java.io.IOException: Cannot run program “node”: CreateProcess error=2, O sistema nÒo pode encontrar o arquivo especificado
at java.lang.ProcessBuilder.start(Unknown Source)
at org.sonarsource.nodejs.NodeCommand$ProcessWrapperImpl.start(NodeCommand.java:144)
at org.sonarsource.nodejs.NodeCommand.start(NodeCommand.java:71)
… 37 common frames omitted
Caused by: java.io.IOException: CreateProcess error=2, O sistema nÒo pode encontrar o arquivo especificado
at java.lang.ProcessImpl.create(Native Method)
at java.lang.ProcessImpl.(Unknown Source)
at java.lang.ProcessImpl.start(Unknown Source)
… 40 common frames omitted

WARNING: WARN: Analyzer working directory does not exist: ‘C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out\3\output-cs’. Analyzer results won’t be loaded from this directory.
INFO: Base dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\websocket-sharp
INFO: Working dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out.sonar\CSharp_CSharp_B357BAC7-529E-4D81-A0D2-71041B19C8DE
INFO: Source paths: AssemblyInfo.cs, Ext.cs, MessageEventArgs.cs, CloseEventArgs.cs, ByteOrder.cs, ErrorEventArgs.cs, WebSocket.cs, Server/WebSocketServer.cs, Net/AuthenticationSchemes.cs, Net/ChunkStream.cs, Net/Cookie.cs, Net/CookieCollection.cs, Net/CookieException.cs, Net/EndPointListener.cs, Net/EndPointManager.cs, Net/HttpConnection.cs, Net/HttpListener.cs, Net/HttpListenerContext.cs, Net/HttpListenerException.cs, Net/HttpListenerPrefixCollection.cs, Net/HttpListenerRequest.cs, Net/HttpListenerResponse.cs, Net/HttpStreamAsyncResult.cs, Net/HttpUtility.cs, Net/RequestStream.cs, Net/ResponseStream.cs, Net/WebHeaderCollection.cs, Server/HttpServer.cs, Net/HttpVersion.cs, Net/HttpStatusCode.cs, Server/WebSocketServiceHost.cs, CloseStatusCode.cs, Fin.cs, Mask.cs, Opcode.cs, PayloadData.cs, Rsv.cs, Net/WebSockets/HttpListenerWebSocketContext.cs, Net/WebSockets/TcpListenerWebSocketContext.cs, Net/WebSockets/WebSocketContext.cs, Server/HttpRequestEventArgs.cs, Net/HttpHeaderType.cs, Net/HttpHeaderInfo.cs, CompressionMethod.cs, WebSocketException.cs, LogData.cs, LogLevel.cs, Logger.cs, WebSocketState.cs, Server/IWebSocketSession.cs, Server/WebSocketSessionManager.cs, Server/ServerState.cs, Net/HttpBasicIdentity.cs, Net/HttpDigestIdentity.cs, Net/NetworkCredential.cs, Server/WebSocketServiceManager.cs, Net/InputState.cs, Net/LineState.cs, Net/ReadBufferState.cs, Net/Chunk.cs, Net/InputChunkState.cs, Net/ChunkedRequestStream.cs, Net/QueryStringCollection.cs, WebSocketFrame.cs, Net/AuthenticationChallenge.cs, Net/AuthenticationResponse.cs, Net/AuthenticationBase.cs, HttpBase.cs, HttpRequest.cs, HttpResponse.cs, Server/WebSocketBehavior.cs, Net/HttpListenerPrefix.cs, Net/ClientSslConfiguration.cs, Net/ServerSslConfiguration.cs, Net/HttpListenerAsyncResult.cs, Net/HttpRequestHeader.cs, Net/HttpResponseHeader.cs, Server/WebSocketServiceHost`1.cs
INFO: Source encoding: UTF-8, default locale: pt_BR
INFO: Index files
INFO: 78 files indexed
INFO: Quality profile for cs: Sonar way
INFO: Sensor JaCoCo XML Report Importer [jacoco]
WARNING: WARN: Analyzer working directory does not exist: ‘C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out\0\output-cs’. Analyzer results won’t be loaded from this directory.
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=0ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
INFO: SCM Publisher is disabled
INFO: ------------- Scan Example2
INFO: Base dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master\Example2
INFO: Working dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out.sonar\CSharp_CSharp_B81A24C8-25BB-42B2-AF99-1E1EACCE74C7
INFO: Source paths: AssemblyInfo.cs, Program.cs, Echo.cs, Chat.cs, App.config
INFO: Source encoding: UTF-8, default locale: pt_BR
INFO: Index files
INFO: 5 files indexed
INFO: Quality profile for cs: Sonar way
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor C# Properties [csharp]
INFO: Sensor C# Properties [csharp] (done) | time=15ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
INFO: SCM Publisher is disabled
INFO: ------------- Scan CSharp
WARNING: WARN: Analyzer working directory does not exist: ‘C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out\2\output-cs’. Analyzer results won’t be loaded from this directory.
INFO: Base dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master
INFO: Working dir: C:\Users\pablo.almeida.nalbatech\Documents\Projetos\projeto2-dotnet-master.sonarqube\out.sonar
INFO: Source encoding: windows-1252, default locale: pt_BR
INFO: Index files
INFO: 0 files indexed
INFO: Sensor JaCoCo XML Report Importer [jacoco]
INFO: Sensor JaCoCo XML Report Importer [jacoco] (done) | time=0ms
INFO: Sensor SonarJavaXmlFileSensor [java]
INFO: Sensor SonarJavaXmlFileSensor [java] (done) | time=0ms
INFO: Sensor C# [csharp]
INFO: Importing 4 Roslyn reports
INFO: Sensor C# [csharp] (done) | time=1281ms
INFO: Sensor Zero Coverage Sensor
INFO: Sensor Zero Coverage Sensor (done) | time=15ms
INFO: SCM Publisher is disabled
INFO: Calculating CPD for 1 file
INFO: CPD calculation finished
INFO: Analysis report generated in 2562ms, dir size=974 KB
INFO: Analysis reports compressed in 359ms, zip size=254 KB
INFO: Analysis report uploaded in 78ms
INFO: ANALYSIS SUCCESSFUL, you can browse http://localhost:9000/dashboard?id=CSharp
INFO: Note that you will be able to access the updated dashboard once the server has processed the submitted analysis report
INFO: More about the report processing at http://localhost:9000/api/ce/task?id=AWgtyTG6I33HtZ1mLjlK
INFO: Task total time: 1:35.313 s
INFO: ------------------------------------------------------------------------
INFO: EXECUTION SUCCESS
INFO: ------------------------------------------------------------------------
INFO: Total time: 1:38.160s
INFO: Final Memory: 16M/330M
INFO: ------------------------------------------------------------------------
The SonarQube Scanner has finished
12:06:41.399 Creating a summary markdown file…
12:06:41.414 Analysis results: http://localhost:9000/dashboard/index/CSharp
12:06:41.414 Post-processing succeeded.

Thanks for the logs! I noticed several messages like this Analyzer working directory does not exist...., for each analyzed project. I suspect that you don’t have Visual Studio 2015 Update 3 (or later) on the build machine, or the MSBuild version that’s used is from older Visual Studio (the MSBuild logs could help here, the version is written in the beginning of the build).

Please make sure you are building with a supported version of MSBuild - from Visual Studio 2015 Update 3 (14.3) and later.