My SonarQube server version is 8.9.0.43852.
I’m trying to do the analysis of a .NET project with gitlab-ci. In order to do so, I’m using this .gitlab-ci.yml:
sonarqube-check:
image: mcr.microsoft.com/dotnet/sdk:latest
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- "mkdir -p /usr/share/man/man1"
- "apt search openjdk-11-jre"
- "apt-get update && apt-get install --yes openjdk-11-jre"
- "dotnet tool install --global dotnet-sonarscanner"
- "export PATH=\"$PATH:$HOME/.dotnet/tools\""
- "dotnet sonarscanner begin /k:\"PROJET-KEY \" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
- "dotnet build My.Project/MyProject.csproj"
- "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
allow_failure: true
only:
- test_sonar # or the name of your main branc
*Note the image used is mcr.microsoft.com/dotnet/sdk since my project is not a .NET CORE project.
With this .gitlab-ci.yml, my pipeline returns me this error:
/usr/share/dotnet/sdk/5.0.301/Microsoft.Common.CurrentVersion.targets(1177,5): error MSB3644: The reference assemblies for .NETFramework,Version=v4.7.2 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 https://aka.ms/msbuild/developerpacks [/Path/To/Project/Project.csproj]
After some research, I have decided to use mono to resolve this problem of framework.
It works well to solve this specific framework problem but it comes with another problem. The builder can’t resolve a assembly, assembly that I know exist on my docker.
Here’s the .gitlab-ci.yml with the mono followed by the logs of the error
sonarqube-check:
image: mcr.microsoft.com/dotnet/sdk:latest
variables:
SONAR_USER_HOME: "${CI_PROJECT_DIR}/.sonar" # Defines the location of the analysis task cache
GIT_DEPTH: "0" # Tells git to fetch all the branches of the project, required by the analysis task
cache:
key: "${CI_JOB_NAME}"
paths:
- .sonar/cache
script:
- "mkdir -p /usr/share/man/man1"
- "apt update && apt install -y mono-complete"
- "export FrameworkPathOverride=/usr/lib/mono/4.7.2-api/"
- "apt-get update && apt-get install -y file"
- "apt search openjdk-11-jre"
- "apt-get update && apt-get install --yes openjdk-11-jre"
- "dotnet tool install --global dotnet-sonarscanner"
- "export PATH=\"$PATH:$HOME/.dotnet/tools\""
- "dotnet sonarscanner begin /k:\"PROJET-KEY \" /d:sonar.login=\"$SONAR_TOKEN\" /d:\"sonar.host.url=$SONAR_HOST_URL\" "
- "dotnet build My.Project/MyProject.csproj"
- "dotnet sonarscanner end /d:sonar.login=\"$SONAR_TOKEN\""
allow_failure: true
only:
- test_sonar # or the name of your main branc
Error log:
/usr/share/dotnet/sdk/5.0.301/Microsoft.Common.CurrentVersion.targets(2202,5): warning MSB3245: Could not resolve this reference. Could not locate the assembly "System.configuration". Check to make sure the assembly exists on disk. If this reference is required by your code, you may get compilation errors.[/Path/To/Project/Project.csproj]
***Note out of the log: It creates all the compilation errors I have
I also have tried to force the path of this assembly but didn’t worked, still have the same error as above. How I tried to for the path, on the MyProject.csproj:
<ItemGroup>
<Reference Include="System.configuration" >
<HintPath> /Path/To/the/assembly/System.Configuration.dll </HintPath>
</Reference>
</ItemGroup>
Since this is not a .NET CORE project, I tried to follow this command, still with the same docker image which is mcr.microsoft.com/dotnet/sdk:latest
SonarScanner.MSBuild.exe begin /k:"project-key" /d:sonar.login="<token>"
MSBuild.exe <path to solution.sln> /t:Rebuild
SonarScanner.MSBuild.exe end /d:sonar.login="<token>"
But instantly fail since SonarScanner.MSBuild.exe can’t find the Method to get the version of SonarQube server:
Also, I have download the .ZIP version 5.2.1 (here’s the link used). The link for the version 5.2.2 seems to be broken so couldn’t get it.
System.MissingMethodException: Method not found: System.Diagnostics.TraceSource System.Net.Logging.get_Http()
Do anyone have a solution for this problem?