# How to scan C# Unity code on Mac?

**URL:** <https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761>\
**Category:** SonarQube Cloud\
**Tags:** dotnet\
**Created:** [December 12, 2021, 3:11pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761 "2021-12-12T15:11:38Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [December 12, 2021, 3:11pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/1 "2021-12-12T15:11:38Z")

</div>

Hi,  
I’m trying to scan C# Unity code manually on my MacBook.  
I saw [SonarCloud setup to analyse Unity project in CI](https://community.sonarsource.com/t/sonarcloud-setup-to-analyse-unity-project-in-ci/26024), and I tried to follow [SonarScanner for .NET | SonarQube Docs](https://docs.sonarqube.org/latest/analysis/scan/sonarscanner-for-msbuild/), but without success.  
I installed .NET Core SDK 2.0, downloaded and using sonar-net-5/sonar-scanner-4.6.2.2472/bin/sonar-scanner  
but I’m still getting

```auto
INFO: Sensor C# [csharp]
WARN: Your project contains C# files which cannot be analyzed with the scanner you are using. To analyze C# or VB.NET, you must use the SonarScanner for .NET 5.x or higher, see https://redirect.sonarsource.com/doc/install-configure-scanner-msbuild.html
INFO: Sensor C# [csharp] (done) | time=2ms

```

What I’m missing?  
In fact, my goal is to integrate Sonarcloud with Github, using Github Actions.  
Is there updated tutorial for that?

TIA, Vitaly

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 13, 2021, 9:53am UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/2 "2021-12-13T09:53:32Z")

</div>

Hey there.

It’s important that you invoke the [Scanner for .Net](https://sonarcloud.io/documentation/advanced-setup/ci-based-analysis/sonarscanner-for-dotnet/) correctly, rather than directly calling the `sonar-scanner` executable. This is noted in the docs.

> In summary, the invocation of the SonarScanner for .NET will depend on the scanner flavor:
> 
> > | Scanner Flavor | Invocation |
> > | --- | --- |
> > | .NET 5 | `dotnet <path to SonarScanner.MSBuild.dll>` etc. |
> > | .NET Core Global Tool | `dotnet sonarscanner begin` etc. |
> > | .NET Core 2.0+ | `dotnet <path to SonarScanner.MSBuild.dll>` etc. |
> > | .NET Framework 4.6+ | `SonarScanner.MSBuild.exe begin` etc. |

In the context of GitHub Actions – there is a tutorial when you create a new project in the SonarCloud UI.

 ![Screenshot 2021-12-13 at 10.51.26](https://europe1.discourse-cdn.com/sonarsource/uploads/sonarcommunity/original/3X/5/6/567b397aa47bab65c460338152d0ac949491173a.png)

---

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [December 13, 2021, 10:01am UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/3 "2021-12-13T10:01:27Z")

</div>

> [@Colin](#):
>
> In the context of GitHub Actions – there is a tutorial when you create a new project in the SonarCloud UI.

Thank you! I tried to follow this tutorial, but I’m not sure what should I use as a build command. Should I install MSBuild via GitHub Actions?

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 13, 2021, 1:42pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/4 "2021-12-13T13:42:22Z")

</div>

How do you build your code today (i.e. if SonarCloud wasn’t in the mix, what build command would you use to build your code?)

---

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [December 13, 2021, 2:17pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/5 "2021-12-13T14:17:44Z")

</div>

Sorry, I didn’t provide the big picture.  
I’m DevOps freelancer and using Sonar for 3+ years with different platforms - Java, NodeJS, PHP, etc.  
Recently I have a customer which developing under Unity for Android. Currently, they build into Unity IDE.  
There is no build configuration file.  
I generated .sln file used “dotnet new sln”, but “dotnet build .” fails with “C:\Program Files\dotnet\sdk\5.0.403\NuGet.targets(131,5): warning : Unable to find a project to restore! [D:\a\BoatAttack\BoatAttack\BoatAttack.sln]”. I tried a few suggestions for fixing nugest config, but without success so far.  
Thank you again, Vitaly  
PS: BTW, is there a way to run some basic analyze using source code only?

```auto
SonarScanner for MSBuild 5.4
Using the .NET Core version of the Scanner for MSBuild
Pre-processing started.
Preparing working directories...
14:13:02.783 Updating build integration targets...
14:13:03.714 Fetching analysis configuration settings...
14:13:04.963 Provisioning analyzer assemblies for cs...
14:13:04.964 Installing required Roslyn analyzers...
14:13:06.705 Provisioning analyzer assemblies for vbnet...
14:13:06.705 Installing required Roslyn analyzers...
14:13:06.736 Pre-processing succeeded.
Microsoft (R) Build Engine version 16.11.2+f32259642 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
C:\Program Files\dotnet\sdk\5.0.403\NuGet.targets(131,5): warning : Unable to find a project to restore! [D:\a\BoatAttack\BoatAttack\BoatAttack.sln]

Build succeeded.

C:\Program Files\dotnet\sdk\5.0.403\NuGet.targets(131,5): warning : Unable to find a project to restore! [D:\a\BoatAttack\BoatAttack\BoatAttack.sln]
    1 Warning(s)
    0 Error(s)

Time Elapsed 00:00:00.28
SonarScanner for MSBuild 5.4
Using the .NET Core version of the Scanner for MSBuild
Post-processing started.
14:13:07.73 The SonarScanner for MSBuild integration failed: SonarCloud was unable to collect the required information about your projects.

```

---

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [December 13, 2021, 2:25pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/6 "2021-12-13T14:25:32Z")

</div>

My customer’s project is private, but I reproduced the same issue with the public Unity demo - [GitHub - vitalykarasik/BoatAttack: Demo Project using the Universal RP from Unity3D](https://github.com/vitalykarasik/BoatAttack).

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 14, 2021, 8:52am UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/7 "2021-12-14T08:52:22Z")

</div>

Hey @vitalykarasik

You’re right – you will need a `.csproj` / `sln` file in order to use the Scanner for .NET. **And,** I don’t know enough about Unity to understand what to do when one isn’t generated by default. I’ll call on someone who might.

---

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [December 14, 2021, 9:22am UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/9 "2021-12-14T09:22:42Z")

</div>

Colin, thank you!  
As I wrote, I generated .sln with “dotnet new sln”  
I’m attaching it for the reference, Vitaly

```auto

Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.30114.105
MinimumVisualStudioVersion = 10.0.40219.1
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
		Debug|Any CPU = Debug|Any CPU
		Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(SolutionProperties) = preSolution
		HideSolutionNode = FALSE
	EndGlobalSection
EndGlobal

```

---

<div class="post-metadata">

**Author:** ![Colin](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/colin/32/55255_2.png) [@Colin](https://community.sonarsource.com/u/Colin)\
**Post date:** [December 14, 2021, 10:10am UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/10 "2021-12-14T10:10:46Z")

</div>

This is fine – but somehow your C# files must also be referenced by the solution / a sub-project. Simply having one in your repository is not enough.

---

<div class="post-metadata">

**Author:** ![Tom\_Howlett](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/tom_howlett/32/22183_2.png) [@Tom\_Howlett](https://community.sonarsource.com/u/Tom_Howlett)\
**Post date:** [December 15, 2021, 1:43pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/13 "2021-12-15T13:43:18Z")

</div>

Hi Vitaly

We don’t have much experience of Unity at the moment and it looks like it doesn’t build using MSBuild so it’s going to be difficult to analyse your project in the usual way.

> [@vitalykarasik](#):
>
> PS: BTW, is there a way to run some basic analyze using source code only?

I’m afraid not.

Sorry!

Tom

---

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [December 15, 2021, 2:16pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/14 "2021-12-15T14:16:32Z")

</div>

Tom, thank you!

> is there a way to run some basic analyze using source code only?  
> Sorry for off-topic, but as far as I understand, Codacy uses Sonar scanner for C#, and it works.

---

<div class="post-metadata">

**Author:** ![Andrei\_Epure](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrei_epure/32/77402_2.png) [@Andrei\_Epure](https://community.sonarsource.com/u/Andrei_Epure)\
**Post date:** [June 1, 2022, 1:20pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/17 "2022-06-01T13:20:42Z")

</div>

Hi @vitalykarasik - is it correct that this is a duplicate of [Scanning C# (Unity) project error - #3 by Andrei\_Epure](https://community.sonarsource.com/t/scanning-c-unity-project-error/55119/3)?

---

<div class="post-metadata">

**Author:** ![vitalykarasik](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/vitalykarasik/32/6737_2.png) [@vitalykarasik](https://community.sonarsource.com/u/vitalykarasik)\
**Post date:** [June 1, 2022, 3:11pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/18 "2022-06-01T15:11:41Z")

</div>

right, it’s the same issue, sorry

---

<div class="post-metadata">

**Author:** ![Andrei\_Epure](https://dub1.discourse-cdn.com/sonarsource/user_avatar/community.sonarsource.com/andrei_epure/32/77402_2.png) [@Andrei\_Epure](https://community.sonarsource.com/u/Andrei_Epure)\
**Post date:** [June 27, 2022, 2:50pm UTC](https://community.sonarsource.com/t/how-to-scan-c-unity-code-on-mac/54761/20 "2022-06-27T14:50:32Z")

</div>

Closed on June 27, 2022, 2:50pm UTC


