Resharper with Sonarqube for a Unity Project: Can it work?

  • which versions are you using
    • SonarQube: 9.2.0
    • Scanner: 4.6.2.2472
    • SonarScanner for MSBuild: 5.4.0.40033
  • what are you trying to achieve
    • I want to get resharper to work with sonarqube for a Unity Project
  • what have you tried so far to achieve this

If I understood correctly the current situation is

  • the resharper-clt-plugin is not maintained anymore and it cannot be installed from the marketplace. (I haven’t tried to manually install it)
  • it should also not be needed anymore, as resharper cli (inspectcode) can be used as roslyn analyzer (maybe?)

In this post, @OlivierK says that

PS: Resharper was initially NOT a roslyn based analyzer, it was ported to roslyn recently. You must run that ported version to get the expect outcome.

Sorry I am rather new to the topic and don’t know how to tell if a resharper version is a roslyn analyzer, or where to find it.
I have so far tried to download a few different versions of resharper as zip, and then basically had the ci run

mono /opt/sonar-scanner-msbuild/SonarScanner.MSBuild.exe begin \
  -k:"$SONAR_PROJECT_KEY" \
  -d:sonar.host.url="$SONAR_HOST_URL" \
  -d:sonar.login="$SONAR_TOKEN" \
  -v:"$SONAR_SNAPSHOT_VERSION"
#msbuild Assembly-CSharp-Editor.csproj
#msbuild Assembly-CSharp.csproj
/opt/resharper/inspectcode.sh \
  --toolset-path=/usr/lib/mono/msbuild/Current/bin/MSBuild.dll \
  -o="${SONAR_TMP_PATH}resharper.xml" \
  --exclude="Assets/ThirdParty/**" \
  --exclude="Assets/Plugins/**" \
  --build \
  "$BUILD_NAME.sln"
mono /opt/sonar-scanner-msbuild/SonarScanner.MSBuild.exe end -d:sonar.login="$SONAR_TOKEN"

This fails with

The SonarScanner for MSBuild integration failed: SonarQube was unable to collect the required information about your projects.

Possible causes:

  1. The project has not been built - the project must be built in between the begin and end steps
  2. An unsupported version of MSBuild has been used to build the project. Currently MSBuild 14.0.25420.1 and higher are supported.
  3. The begin, build and end steps have not all been launched from the same folder
  4. None of the analyzed projects have a valid ProjectGuid and you have not used a solution (.sln)

It should not be reason 3. or 4.
In the resharper docs I read that resharper itsself will build the solution - so I assume it is not reason 1. (but maybe this fails somehow, the logs are quite big, i am not sure about this)
When I uncomment one of the msbuild lines above, it appears to work, but:
The msbuild step reports things like for example private field with Unitys [SerializeField] attribute as unassigned (CS0649).
One of the reasons for using resharper is, that with its Unity plugin, it will not report these false positives.
However, while resharper does properly write its analysis to resharper.xml, sonarscanner doesnt pick anything up, I see none of the issues in sonarqube (I would attach a log file, but with 4.3MB it is just above the limit).
So I believe, the resharper Version that I do have is not a roslyn-analyzer.

Does a usable roslyn-analyzer Version of resharper exist?
All I have found is this repository which seems has been abandoned in 2019.
Is there still a chance for me to get ti to work?

Edit:
Also, if I hat a Roslyn analyzer or would write some hack that transforms the report to the generic import-format, I could still not use the issues in a quality gate - that would be rather sad. Is there any way to make that work?

I don’t know if the wayInspectCode builds code is compatible with the SonarScanner for .NET or not.
Have a look at the log output from the InspectCode step: there will be log entries starting Sonar: if the Sonar build targets are being executed.

As far as I am aware, Resharper is still not Roslyn-based (although I could be wrong). JetBrains Rider now has support for running Roslyn analysis in addition to Resharper, but that is a separate thing.
There is nothing in the InspectCode documentation about whether Roslyn analyzers are executed or not, so my assumption is that that are not.

However, the documentation does suggest that running both a “normal” MSBuild step and the InspectCode step should not be too expensive.

If you want to stop CS0649 from reporting, add a normal Ruleset file to your projects and disable the rule in the ruleset. The Scanner will combine your ruleset with the ruleset it generates from the Quality Profile.

1 Like

Hello @duncanp and thank you for your Answer (and sorry for the delayed reply, bigger release comming up here).
Since I do not see the Sonar messages, I think that, just as you say, InspectCode simply is not compatible.

Now I have already added back the normal buildcode before resharper.
And have also made it skip issues that I don’t want it to report. did it with cl args for now like this:

-property:nowarn=“169%3b649”

(apparently you have to URL-escape the semicolon for multiple warning, otherwise it does not work.)

Now I still have the problem that, if resharper doesn’t send its Issues to sonarqube, there’s no point running it at all.
The reason I want to run resharper isn’t just that it doesn’t report certain things that make no sense with unity, but it also additionally reports a lot of things that I do want to be able to see. (Probably I should have mentioned this)

As far as I understand the situation now, I have 2-ish options:

  1. transform the build-report from resharper yself with a script to the generic import format and feed that to sonarqube - thereby giving up on the options to include the resharper issues in quality-gate, or enable/disable rules

  2. go the sonatrqube-plugin route, so
    Maybe somehow hope that I can get the no-longer maintained reshaprer plugin to work, maybe contact the author, maintain it myself or something…

Do I understand that correctly?

@IARI

  1. the Importing Third-Party Issues page doesn’t list C# as one of the languages that supports the generic reports format, so I don’t think this option would work.

  2. checking whether the existing plugin works seems like a better bet.

1 Like

thanks - it turns out the plugin still works with 9.2.1.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.