MSBuild.exe is failing when scanning C# files

Hi Team ,

I am scanning C# code files with the sonar-scanner for .NET method. For this I am using the below link and tool Microsoft .NET Framework 4.6 scanner flavour for scanning C# files. During build phase I am facing below issue.

When I checked the MSBuild.exe version I am getting below. Not sure what is happening. Can anyone pls help me on this?

image

Any issues with Microsoft .NET Framework?

Thanks,
Prasad.

Hi Prasad

Although you should be able to analyse a project targeting an older version of the .NET Framework you will need to have at least .NET Framework 4.6 SDK installed for the analysis to run.

Hope that helps

Tom

Hi Tom,

Thank you for your reply. If you can see the screenshot, it is having the higher version of the .NET Framework 4.8.3761.0. How to analyse a project targeting an older version of the .NET Framework?

We have production build node having above stated version of .NET framework, but can’t change on the node as it may impact other things on the node.

Thanks,
Prasad.

@Tom_Howlett Any help that you do on this? I am completely Stuck on this.

Hi Prasad

Your screenshot shows that you have MSBuild 4.8 that I believe was shipped with .NET Framework 4.0. You will need at least Framework 4.6 installed for the analysis to run. If you are unable to put a later version on this node I suggest you try running the analysis on a separate node with a later version of the framework installed.

Good luck

Tom

Hi Tom,

When we try to install the Framework, it is giving an issue like below:

image

Also these machines have already 4.7 .NET Framework already installed.

image

Not sure why is it saying the machines are having .NET Framework 4.0 only. Could you enlighten me on this?

Thanks,
Prasad.

@prasad-clouduser those issues are not related to the analysis; they are related to the underlying build.

The original error message

The is the underlying issue that is stopping your build from working, and is unrelated to Sonar analysis.
Logically, when building an application there are two different versions of .NET are relevant:
(1) the version of .NET (and hence MSBuild) that is being used to execute the build, and
(2) the version of .NET that the built assemblies are targeting i.e. are intended to run against.

These versions can be different. However, if they are then the build machine will need to the SDK/Targeting Pack for the target version of .NET. See the MS docs for more information.

As a first step, get the build working correctly without the scanner begin and end steps.

.NET folder version name does not match the installed version number
image

This is expected. If you check the file properties of a file inside the v4.0.30319 directory (e.g. msbuild.exe) you will see the file and product versions of the file are different e.g. v.4.8.3761.0 in your case.