sonar-scanner-msbuild icon indicating copy to clipboard operation
sonar-scanner-msbuild copied to clipboard

Scanner should allow to analyze loose .js/.ts files easily

Open Evangelink opened this issue 6 years ago • 14 comments

Description

When using a project mixing C# and JS/TS it is currently not easy to have the analysis of all files in one go.

Currently you have to either:

  1. Create some "fake" Visual Studio project referencing all your .js/.ts files (using wildcard is a good way not to have to update references all the time).
  2. Analyze twice, one for C# and one for .js/.ts against 2 different SonarQube/SonarCloud projects

Related information

  • Usage: Standalone/TFS/VSTS/Jenkins/Cake

Evangelink avatar Mar 15 '18 15:03 Evangelink

Hi, would this also cover loose .sql files ? I can't find a way to scan both t-sql and c# into the same sonar project. I have a collection of sql files inside a folder, which I don't want to be part of any csproj file and I believe this means they are ignored by the msbuild scanner...

robjmberry avatar Mar 15 '18 23:03 robjmberry

We decided to remove this ticket from the 4.2 milestone as we have identified a couple of cases requiring further discussions.

Evangelink avatar Apr 13 '18 14:04 Evangelink

Taking into account the new kind of hybrid technology projects this is a MUST. so far I cannot update the scanner because the projects contain a mixture of languages. and the worst part is that I cannot update the plugin because it does not run without the scanner-msbuild, therefore if I update the plugin and run it with the sonar-scanner i wont get the c# information.

bootrider avatar May 25 '18 12:05 bootrider

is there a solution available for this because i also have the same issue . I have C# and typescript files in one project and one analysis doesn't gives the the entire result.

Jyoti492 avatar Jul 03 '18 11:07 Jyoti492

@Jyoti492 by "in one project" do you mean in one MSBuild project or in one SonarQube project?

duncanp-sonar avatar Jul 09 '18 13:07 duncanp-sonar

I mean a SonarQube project

bootrider avatar Jul 23 '18 15:07 bootrider

Read in one of the issue lists for Sonar that it was somehow possible to have both .cs and .js files scanned within context of MSBUILD. Something about the .js files had to be specifically referenced within one of the .csproj files. I have a project that contains a <Content> block for each .js file. While the .cs files show up in the scan results, none of the .js files are included.

Is there a different way I should be referencing the .js files?

I wish I could find the issue... but I believe it was under the sonar-csharp scanner.

BTW... I'm not the developer... just trying to provide SonarQube scanning to existing projects on team I am supporting.

dwayne-mss avatar Aug 24 '18 19:08 dwayne-mss

I am trying to make it together, but it works for either C# or JavaScript. Howver I could see the code coverage for both but not getting the combined unit test counts for C# and JS

C# Test Counts Only

#dir %system.MSBUILD_SONARQUBE_RUNNER%
#dir %env.SONAR_RUNNER_HOME%\bin
#dir %teamcity.dotCover.home%
#dir %teamcity.tool.dotCover%
$workdir="%teamcity.build.checkoutDir%"
$coverageReport="$workdir\Integration\dotCover.html"
$testResults="$workdir\TestResult.xml"
$jsTestResults="$workdir\src\Planning.Spa\jstest_report.xml"

$sonar=%system.MSBUILD_SONARQUBE_RUNNER%\MSBuild.SonarQube.Runner.exe 
begin /k:"com.comp:Planning" /n:"Integration" /v:"%build.number%" 
/d:sonar.cs.dotcover.reportsPaths="$coverageReport" 
/d:sonar.cs.nunit.reportsPaths="$testResults" 
/d:sonar.test.inclusions="Offer/App/**/*.spec.js" 
/d:sonar.verbose="true" 
/d:sonar.exclusions="Offer/Scripts/**, Offer/libs/**, Offer/App/**/*.spec.js" 
/d:sonar.javascript.lcov.reportPaths="coverage/report/lcov.info" 
/d:sonar.testExecutionReportPaths="$jsTestResults"


JavaScript Test Counts only (It overrides c# count :( )

This happens when I set something like /d:sonar.tests="Offer/App"


#dir %system.MSBUILD_SONARQUBE_RUNNER%
#dir %env.SONAR_RUNNER_HOME%\bin
#dir %teamcity.dotCover.home%
#dir %teamcity.tool.dotCover%
$workdir="%teamcity.build.checkoutDir%"
$coverageReport="$workdir\Integration\dotCover.html"
$testResults="$workdir\TestResult.xml"
$jsTestResults="$workdir\src\Planning.Spa\jstest_report.xml"

$sonar=%system.MSBUILD_SONARQUBE_RUNNER%\MSBuild.SonarQube.Runner.exe 
begin /k:"com.comp:Planning" /n:"Integration" /v:"%build.number%" 
/d:sonar.cs.dotcover.reportsPaths="$coverageReport" 
/d:sonar.cs.nunit.reportsPaths="$testResults" 
/d:sonar.tests="Offer/App" 
/d:sonar.test.inclusions="Offer/App/**/*.spec.js" 
/d:sonar.verbose="true" 
/d:sonar.exclusions="Offer/Scripts/**, Offer/libs/**" 
/d:sonar.javascript.lcov.reportPaths="coverage/report/lcov.info" 
/d:sonar.testExecutionReportPaths="$jsTestResults"

Does anything can be done to combine both test counts in SonarQube dashboard?

Here you could see more details on how I created JS coverage report https://stackoverflow.com/questions/51878860/sonarqube-and-lcov-report-could-not-resolve-file-paths

MuraliM avatar Sep 03 '18 14:09 MuraliM

I also spent quite some time trying to get this work. We have a "hybrid" project consisting of a ASP.NET Core Web API (C#) and a SPA (TypeScript). This is a quite common setup that SonarQube needs to support.

We use MsTest/karma to test the C#/TypeScript code.

Our C# unit tests produce the following reports:

  • Coverage: OpenCover format file (path param: sonar.cs.opencover.reportsPaths)
  • Execution results: TRX format file (path param: sonar.cs.vstest.reportsPaths)

Our TypeScript unit tests produce the following reports:

  • Coverage: LCOV format file (path param: sonar.typescript.lcov.reportPaths)
  • Execution results: Sonar Generic Execution Test Data format file (path param: sonar.testExecutionReportPaths)

Everything works fine with the Coverage results - C# and TS coverage is merged nicely in SonarQube. But the Execution results seem impossible to combine. With the configuration above, the sonar scanner reports that the test files referenced in the "Generic Execution" report are unknown.

I therefore tested adding the sonar.tests and sonar.test.inclusions params, but no value combinations here produce the desired outcome:

If I specify paths/patterns for both the C# and TS test using these params, I get an error from the scanner saying that it can't add C# files already added.

If I only specify paths/patters the TS tests, in the inclusions, the C# test results are overridden and not shown in SonarQube, only the TS execution results appear.

Can the sonar scanner for MSBuild merge TRX test result files for C# with "generic sonar" results from other so that the combined results show up in SonarQube somehow?

josundt avatar Jun 11 '19 10:06 josundt

Related MMF: https://jira.sonarsource.com/browse/MMF-1411

duncanp-sonar avatar Aug 12 '19 15:08 duncanp-sonar

We also ran into the issue of a TS front-end with a C# backend. We don't do the TS work in VS, but VS Code instead. Thus they aren't part of any csproj files. Right now I'm just doing 2 separate SQ projects to do this, but I really wish I could just do 1.

iamwyza avatar Oct 13 '19 19:10 iamwyza

Hope we can get a resolution to this issue. Can we confirm here that it is possible to reference TS files in .csproj to get the analysis working?

kdevcse avatar Oct 25 '19 15:10 kdevcse

@klewiscse yes, that will work. See this community forum answer for more information.

duncanp-sonar avatar Oct 25 '19 15:10 duncanp-sonar

I can confirm that we have a comparable setup like @iamwyza C# backend with Angular Frontend. C# backend is done in VS while Angular Development happens in VS Code. We will go for the community forum answer with slight adaptions. We only include the TS-files if a certain MsBuild property is set as we only do the analyses on our CI pipeline:

<ItemGroup Condition=" '$(SonarQube)' != '' ">
    <None Include="Angular\**\*.ts" Visible="False" />
</ItemGroup>

Danielku15 avatar Oct 29 '19 17:10 Danielku15