Getting error "/usr/lib64/dotnet/sdk/8.0.104/NuGet.targets(156,5): error : 'latest' is not a valid v

When I run pipeline, in sonarquibe analysis stage getting below error:
/usr/lib64/dotnet/sdk/8.0.104/NuGet.targets(156,5): error : ‘latest’ is not a valid version string. (Parameter ‘value’)

This is my pipeline code in the below:–

 stage('SonarQube Analysis with .NET') {
            steps {
                script {
                    withSonarQubeEnv('sonar-scanner') {
                        dir('TLH-Dev-Backend') {
                            sh '''
                                set -e
                                dotnet tool install --global dotnet-sonarscanner || true
                                
                                # Use your NuGet.Config explicitly here
                                dotnet restore /var/lib/jenkins/workspace/DEV/TLH-Dev-Backend/6-Construction/aspnet-core/TLH.sln --configfile ../../NuGet.Config

                                dotnet sonarscanner begin \
                                  /k:"KleensyBackendOlddev" \
                                  /n:"KleensyBackendOlddev" \
                                  /v:"1.0" \
                                  /d:sonar.login="squ_c53a1d25eabc0b5de4269486e6c298a592ba4cf1" \
                                  /d:sonar.inclusions="**/*.cs" \
                                  /d:sonar.host.url="http://172.16.7.213:9000" 
                                dotnet build /var/lib/jenkins/workspace/DEV/TLH-Dev-Backend/6-Construction/aspnet-core/TLH.sln  
                                dotnet sonarscanner end /d:sonar.login="squ_c53a1d25eabc0b5de4269486e6c298a592ba4cf1"
                            '''
                        }
                    }
                }
            }
        }

Getting error:—
/usr/lib64/dotnet/sdk/8.0.104/NuGet.targets(679,5): error : File '/var/lib/jenkins/workspace/DEV/TLH-Dev-Backend/TLH-Dev-Backend/NuGet.Config' does not exist. [/var/lib/jenkins/workspace/DEV/TLH-Dev-Backend/6-Construction/aspnet-core/CustomerApp/TLH.CustomerApp.CustomerApplicationService/TLH.CustomerApp.CustomerApplicationService.csproj]

What need to change not understand. But when run pipeline command manually in workspace, that time no error give. Please suggest me what need to do.

Hi there,

Based on the errors provided, it looks like the problem is not with SonarQube analysis itself, but rather with the .NET build/restore step—specifically with NuGet configuration.

This looks like NuGet is trying to restore packages with an invalid version specification. This likely comes from a package reference or a dependency listed as version=“latest” in your *.csproj or packages.config, or even as a package source in your NuGet.Config. NuGet does not recognize “latest” as a valid version; you should specify an explicit version number.

  • This is indicating that the path to your NuGet.Config might be misconfigured or missing in the Jenkins/scenario pipeline (even though it may exist locally). You appear to be passing it here explicitly. Any particular reason?

Since you mention that running the command manually in the workspace works, but it fails in the pipeline, this can mean that the configuration/environment differs between your manual run and the pipeline run. Perhaps the working directory or path to NuGet.Config is different in Jenkins.

In any case, I suggest you remove the SonarQube parts of your pipeline for now – see if the error persists, and focus on having a working build before adding the SonarScanner back.