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

Running the begin step with the scanner dotnet tool fails if there are multiple projects in the same folder.

Open csaba-sagi-sonarsource opened this issue 2 years ago • 7 comments

Description

If there are multiple projects in the same folder from where the begin step is run, it fails with the following error: "Specify which project file to use because this 'Path to the folder' contains more than one project file."

Important to note again that this is only the case if the command is run with dotnet sonarscanner, the begin step is successful if run with SonarScanner.MSBuild.exe or dotnet sonarscanner.msbuild.dll.

Related community thread: https://community.sonarsource.com/t/specify-which-project-file-to-use-on-running-scanner-for-net-core-project/47908

Related MS bug: https://github.com/dotnet/sdk/issues/7226

Repro steps

  1. Create (at least) two projects in the same folder

  2. Run the begin step with dotnet sonarscanner

Expected behavior

The begin step succeeds.

Actual behavior

The begin step fails.

Known workarounds

Use SonarScanner.MSBuild.exe or dotnet sonarscanner.msbuild.dll to run the begin step,

OR

Create a solution that references the projects and build the solution.

Related information

  • SonarScanner for MSBuild version: 5.3.1

csaba-sagi-sonarsource avatar Nov 12 '21 13:11 csaba-sagi-sonarsource

I ran into the same problem. By the way, I think I can specify a sln file to solve this problem, but I don't know how to specify it..😂

89trillion-feiyang avatar Nov 20 '21 12:11 89trillion-feiyang

@89trillion-feiyang the MS docs should help.

duncanp-sonar avatar Nov 22 '21 11:11 duncanp-sonar

@89trillion-feiyang the MS docs should help.

Thanks.

89trillion-feiyang avatar Nov 24 '21 02:11 89trillion-feiyang

For me it appears the suggested workaround does not work.

dotnet sonarscanner.msbuild.dll begin \
      -k:"<mysonarprojectid>" \
      -d:sonar.host.url="$SONAR_HOST_URL" \
      -d:sonar.login="$SONAR_TOKEN" \
      -v:"$CI_COMMIT_TAG" \
      -d:sonar.exclusions=Assets/**/Plugins/**/*
image

Its also impossible to have only one Project, because i have to check two projects what can I do?

IARI avatar Nov 26 '21 15:11 IARI

Hi @IARI, you can ask for help to find some workaround to your specific scenario in our community forum that is watched by our community and more SonarSourcers. Where you can also provide more details about your project structure and actions that you've tried.

This repository is our technical backlog to track issues.

Thanks @pavel-mikula-sonarsource. I have posted some more questions in the forum by now already - but now that I have written this here already let me resolve it here: The problem was that actually that I had sonarscanner not installed properly and didn't exist - that apparently yields the very same error message.

IARI avatar Nov 29 '21 12:11 IARI

I was unable to get the first workaround to work, but can confirm that creating a separate .sln file outside of the directory with too many .csproj files will work.

piersb-audiomob avatar Feb 22 '22 15:02 piersb-audiomob