Can't run SonarQube via dotnet with more than one .csproj file in the directory

I’m trying to evaluate SonarQube, but can’t get the scanner to run because dotnet errors if there is more than one .csproj in the working directory.

  • which versions are you using (SonarQube, Scanner, Plugin, and any relevant extension)
    SonarQube:latest, dotnet 5.0.207, sonarscanner 5.4.1

  • what are you trying to achieve
    Run SonarScanner SonarScanner for .NET | SonarQube Docs

  • what have you tried so far to achieve this
    dotnet sonarscanner begin /k:"SonarQube-Test" /"http://localhost:9000" /d:sonar.login="[numbers]"

gives the following response:

Specify which project file to use because this '/Users/piersb/Development/AudioMob/unity-plugin' contains more than one project file.

Chasing it down, it looks like this is a problem with dotnet itself - invoke a dotnet tool with multiple *proj in same directory is not possibile · Issue #7226 · dotnet/sdk · GitHub whenever there’s more than one project file in a directory. Unfortunately this is a Unity project - and Unity insists on generating more than one .csproj file

I tried the workaround described in dotnet references GitHub - benmccallum/dotnet-references: A dotnet global tool for manipulating references in solution and project files

mkdir temp && cd temp && dotnet references fix -ep ../ -wd .. -rupf

but that bombs out with a long list of errors starting with

Could not find csproj file path for: 'Include="AudioMobScripts.csproj'.
Exception: System.InvalidOperationException: Sequence contains no matching element
   at System.Linq.ThrowHelper.ThrowNoMatchException()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source, Func`2 predicate)
   at BenMcCallum.DotNet.References.Common.FindCsProjFilePath(String[] csProjFilePaths, String csProjFileName) in /home/runner/work/dotnet-references/dotnet-references/src/dotnet-references/Common.cs:line 41

Has anyone else encountered this problem? If so have you found a solution?

Hi @piersb - welcome to the community.

This does seems like an odd and somewhat unfortunate behaviour of dotnet. We have an open issue (S4NET#1103), although it isn’t clear that it’s something we can fix.

However, our issue does list a couple of workarounds that you could try.

This topic was automatically closed after 11 days. New replies are no longer allowed.