C# .NET framework 4.6 code analyzing on Linux platform

Unable to execute static code analysis of project created in C# .Net Framework 4.6 on linux platform

Next error prompt:

  • dotnet build
    MSBuild version 17.7.3+8ec440e68 for .NET
    Determining projects to restore…
    Nothing to do. None of the projects specified contain packages to restore.`

/usr/share/dotnet/sdk/7.0.402/Microsoft.Common.CurrentVersion.targets(1241,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at .NET SDKs downloads for Visual Studio [/opt/atlassian/pipelines/agent/build/myproj.csproj]

On the sonarqube server machine (EC2 aws instance) the C# plugin is installed:
sonar-csharp-plugin-9.8.0.76515.jar

Version on sonarqube : 10.2.1.78527

Could you please advise about it?

Thank you in advance!

Hey there.

.NET 4.6 is Windows-only – so you won’t be able to build it on a Linux platform, which is a prerequisite for being able to analyze it with SonarQube (building it, not specifically with Linux).

1 Like

Hi, and thank you for the reply !!

Recently I tried it on the win-based EC2 instance and got the same error !
The error was repeated even for the .NET framework 4.6 has been installed.

I tried to run bitbucket pipeline …
Does it make sense if bitbucket pipeline is based linux platform?

What is your suggestion to run sonarqube code analysis on .Net framework 4.6 code?

What is most important for you is that first, you have a working build.

Only then should you think about bringing in SonarQube analysis.

That first part you’re going to have to debug yourself – it’s outside the scope of this community.

Thank you for your reply !

I have .NET framework 4.6 solution that passes build without errors and could be run !

SonarQube definition is that it is capable to make analysis with C# code, right?
I think there should not be any limitation with it over bitbucket source control, isn’t it?

If we have any limitation so I would be appreciated you will list it please !

Great! Now you can follow the instructions to install and invoke the .NET Framework scanner.

I’m not really sure what you mean by the rest of your question.

Thanks!

The question was to explain how to make it work
with bitbucket pipeline that is obviously Linux-based.

SonarQube dashboard has the option to run analysis with bitbucket pipeline.
It should run static code analysis for .NET framework 4.6 but it fails

Could you please help to adjust next yml code :

===============================
image: mcr.microsoft.com/dotnet/sdk:7.0

definitions:
steps:
- step: &build-step
name: SonarQube analysis
caches:
- dotnetcore
- sonar
script:
- apt-get update
- apt-get install --yes --no-install-recommends openjdk-17-jre
- dotnet tool install --global dotnet-sonarscanner
- export PATH=“$PATH:/root/.dotnet/tools”
- echo $SONAR_HOST_URL
- echo $SONAR_TOKEN
- echo $SONAR_LOGIN
- dotnet sonarscanner begin /k:“somoto_configurableedge_AYsYxV5Dbg9hlRJviG2o”
/d:“sonar.token=${SONAR_TOKEN}” /d:“sonar.host.url=${SONAR_HOST_URL}”
/d:“sonar.login=${SONAR_LOGIN}”
- cd installertemplate
- ls -l
- dotnet build
- dotnet sonarscanner end /d:“sonar.token=${SONAR_TOKEN}”
caches:
sonar: ~/.sonar

pipelines:
branches:
‘{master}’:
- step: *build-step

=======================

Thank you in advance !

What happens when you run this pipeline? What errors/logs do you get?

There are the errors in my first post in our conversation, about target framework missing:

/usr/share/dotnet/sdk/7.0.402/Microsoft.Common.CurrentVersion.targets(1241,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.6 were not found. To resolve this, install the Developer Pack (SDK/Targeting Pack) for this framework version or retarget your application. You can download .NET Framework Developer Packs at .NET SDKs downloads for Visual Studio [/opt/atlassian/pipelines/agent/build/myproj.csproj]

I think we’re going in circles. Let’s start with this:

Great! Can you share the Bitbucket Pipeline where you have a solution that passes the build?

Yes, probably ))

Sorry but may be I’m missing something - not exactly understand what do you mean “share bitbucket pipeline”

Bitbucket pipeline configuration yml file:

image: mcr.microsoft.com/dotnet/sdk:7.0

definitions:
steps:
- step: &build-step
name: SonarQube analysis
caches:
- dotnetcore
- sonar
script:
- apt-get update
- apt-get install --yes --no-install-recommends openjdk-17-jre
- dotnet tool install --global dotnet-sonarscanner
- export PATH=“$PATH:/root/.dotnet/tools”
- echo $SONAR_HOST_URL
- echo $SONAR_TOKEN
- echo $SONAR_LOGIN
- dotnet sonarscanner begin /k:“somoto_configurableedge_AYsYxV5Dbg9hlRJviG2o” /d:“sonar.token=${SONAR_TOKEN}” /d:“sonar.host.url=${SONAR_HOST_URL}” /d:“sonar.login=${SONAR_LOGIN}”
- cd installertemplate
- ls -l
- dotnet build
- dotnet sonarscanner end /d:“sonar.token=${SONAR_TOKEN}”
caches:
sonar: ~/.sonar

pipelines:
branches:
‘{master}’:
- step: *build-step


Bitbucket repository:

Root directory contains two files:

  • .gitignore
  • bitbucket-pipelines.yml

two subfoders:

  • folder1
  • folder2
    • this folder actually contains solution and the project of C#

.csproj file:

<?xml version="1.0" encoding="utf-8"?> Debug AnyCPU {E04922F1-ECA3-44B6-B164-D4345634793D} WinExe ConfigurableEdge MyAssembly v4.6 512 {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 4 true true publish\ true Disk false Foreground 7 Days false false true 0 1.0.0.%2a false false true AnyCPU true full false bin\Debug\ DEBUG;TRACE prompt 4 AnyCPU pdbonly true bin\Release\ TRACE prompt 4 favicon.ico 4.0 MSBuild:Compile Designer CloseWindow.xaml dclWindow.xaml Screen3.xaml Designer MSBuild:Compile Designer MSBuild:Compile Designer MSBuild:Compile MSBuild:Compile Designer App.xaml Code OfScreen.xaml StScreen.xaml MainWindow.xaml Code Designer MSBuild:Compile Designer MSBuild:Compile Code True True Resources.resx True Settings.settings True ResXFileCodeGenerator Resources.Designer.cs SettingsSingleFileGenerator Settings.Designer.cs




False
Microsoft .NET Framework 4.6 %28x86 and x64%29
true


False
.NET Framework 3.5 SP1
false


Could you please advise what is missing more or another way to share
bitbucket pipeline?

Thank you in advance!

you can try it dockerized with

    • mcr.microsoft.com/dotnet/framework/sdk:4.8

but be aware that these are exclusively windows container instances and the do not understand apk-get install and probably will need the MSBuild approach in Colin’s link :slight_smile:
tricking around with mono on custom images or https://hub.docker.com/_/mono/ may be an option