0

I have this situation ,i trying to build and connect my pipeLine with sonarCloud i have a .net 5.0.x project and .net core 3.1.x , when build the project normally works ok , but when start to add the sonar cloud task starst to fail.

with the next yalm my build is working fine :

trigger:
- qa
- develop
- master

resources:
- repo: self

variables:
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build image
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: 'windows-latest'
    steps:


    - task: UseDotNet@2
      displayName: 'Install .NET 5.x.x SDK'
      inputs:
        version: '5.0.x'
        performMultiLevelLookup: true
        includePreviewVersions: true # Required for preview versions
    
    - task: UseDotNet@2
      displayName: Use Dot Net Core 3.1.x
      inputs:
        packageType: 'sdk'
        version: '3.1.x'

    - task: DotNetCoreCLI@2
      inputs:
         command: 'build'
         projects: '**/*.sln'
      displayName: 'dotnet build'

But when i add SonarCloudPrepare@1 before my build :

trigger:
- qa
- develop
- master

resources:
- repo: self

variables:
  tag: '$(Build.BuildId)'

stages:
- stage: Build
  displayName: Build image
  jobs:  
  - job: Build
    displayName: Build
    pool:
      vmImage: 'windows-latest'
    steps:


    - task: UseDotNet@2
      displayName: 'Install .NET 5.x.x SDK'
      inputs:
        version: '5.0.x'
        performMultiLevelLookup: true
        includePreviewVersions: true # Required for preview versions
    
    - task: UseDotNet@2
      displayName: Use Dot Net Core 3.1.x
      inputs:
        packageType: 'sdk'
        version: '3.1.x'

    - task: SonarCloudPrepare@1
      inputs:
        SonarCloud: 'tp-survey'
        organization: 'teleperformance-sonarcloud'
        scannerMode: 'MSBuild'
        projectKey: tp-cm-back-survey
        projectName: 'tp-cm-back-survey'
        extraProperties: |       
          sonar.exclusions="**/bin/**/*,**/obj/**/*,**/Migrations/**,**/*.dll"
          sonar.coverage.exclusions="test/**"
          sonar.cs.roslyn.ignoreIssues=true
          sonar.verbose=true
    - task: DotNetCoreCLI@2
      inputs:
         command: 'build'
         projects: '**/*.sln'
      displayName: 'dotnet build'

I getting this error :

Command-line syntax error : 'D:\a\1\s\TPSurveyUnitTest\bin\Debug\.netcoreapp,version=v5.0\TPSurveyUnitTest.dll.RoslynCA.json' is not a valid value for the '/errorlog:' option. The value must be of the form '<file>[,version={1|1.0|2|2.1}]'. [D:\a\1\s\TPSurveyUnitTest\TPSurveyUnitTest.csproj]
    181 Warning(s)
    1 Error(s)

Why are doing wrong ?

i tried adding the restore task but the same error. Thanks in advance.

Ivan Fontalvo
  • 433
  • 4
  • 21

2 Answers2

0

The SonarCloud tasks require .NET Core 2.x to be available in the machine. So your fix will be by adding this task before the SonarCloudPrepare task

- task: UseDotNet@2
  displayName: 'Install .Net Core sdk 2.1.x (needed for sonar scanner)'
  inputs:
    version: 2.1.x

- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: 'restore'
    projects: '**/*.csproj'

This is mentioned here in the sonarsource community issue.

https://community.sonarsource.com/t/dotnet-core-3-0-dotnet-sonarscanner/14753

Update:

You should also do dotnet restore before running the scanner.

  • I going to try and let you know, thanks !! – Ivan Fontalvo May 31 '21 at 21:32
  • Same error : Error analysis dotnet build (DotNetCoreCLI) error CS2046(0,0): Error : 'D:\a\1\s\TPSurveyUnitTest\bin\Debug\.netcoreapp,version=v5.0\TPSurveyUnitTest.dll.RoslynCA.json' is not a valid value for the '/errorlog:' option. The value must be of the form '[,version={1|1.0|2|2.1}]'. – Ivan Fontalvo May 31 '21 at 21:43
  • @IvanFontalvo Sorry just noticed you didn't do restore before running the sonar scanner ^^ Answer updated. – Ibrahim Abdelkareem May 31 '21 at 21:54
  • @IvanFontalvo My bad the error stating that you should use the 2.1 version of .NET Core SDK. However, when I had the same issue, .NET Core 2.2.x works for me. Try using .NET Core 2.1 instead of 2.2. I edited the answer once more ^^ – Ibrahim Abdelkareem Jun 01 '21 at 08:55
  • This is weird! I have a very similar setup and it's working fine the only problem was the .NET Core version 2.x isn't available. But this looks like another bug you're encountering. My setup however doesn't contain any of the extraProperties you're having. It shouldn't be a problem having them but maybe if you try to remove them and trigger another build. – Ibrahim Abdelkareem Jun 01 '21 at 21:02
  • Let us [continue this discussion in chat](https://chat.stackoverflow.com/rooms/233202/discussion-between-ivan-fontalvo-and-ibrahim-abdelkareem). – Ivan Fontalvo Jun 01 '21 at 21:38
0

We tried many of the methods that are indicated in the article. The following helped, the following settings were added to the project (.csproj ): TEST .csproj

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<OutputPath>..\YourProductPath\bin\Tests\</OutputPath>

MAIN .csproj

<AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
<AppendRuntimeIdentifierToOutputPath>false</AppendRuntimeIdentifierToOutputPath>
<OutputPath>..\YourProductPath\bin\Release\</OutputPath>

In the pipeline, change the build from .sln to .csproj

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: '$(Build.SourcesDirectory)/YourProductPath/YourProduct.csproj'
    arguments: '--configuration $(BuildConfiguration)'