sonar-scanner-msbuild
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.
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
-
Create (at least) two projects in the same folder
-
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
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 the MS docs should help.
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/**/*
Its also impossible to have only one Project, because i have to check two projects what can I do?
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.
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.