Please Update your pipeline to MsBuild 16 or Higher

ALM/CI Used: Azure DevOps
Language of repo - c#, javascript

I’m having an issue whereby my SonarScans are showing the “Last Analysis has warnings” message. The message states that:

The analysis using MsBuild 15 is deprecated. Please update your pipeline to MsBuild 16 or higher.

I believe I have forced MSBuild 16.0 to run but these alerts still persist. I can confirm with the logs that MSbuild 16.0 is running however there maybe something I have missed and maybe it is reverting back.

I’m at a bit of a loss. Am I missing something? I can provide some logs privately upon request if required.

Pipeline files:

  • Sonar.yml
  • Sonar-template.yml

Sonar.yml


variables:  
  NUGET_PACKAGES: $(Build.SourcesDirectory)\.nuget\packages
  BuildConfiguration: 'Release'
  BuildPlatform: 'AnyCPU'
  msBuildVersion: '16.0'
  projectName: 'core' # Something must be declared here to allow the jobs to validate the service connection
  projectName_alt: 'Core' # Something must be declared here to allow the jobs to validate the service connection

- stage: RunSonarcloud
  dependsOn: PipelineSetup
  
  jobs:
  - job: Academy
    cancelTimeoutInMinutes: 1
    variables:
      projectName : 'academy'
      projectName_alt : 'Academy'
      run_tests : false
    pool:
      vmImage: windows-2019
    steps:
    - template: sonar-template.yml

sonar-template.yml

steps:
- checkout: self
  fetchDepth: 0
  fetchTags: false
- task: NuGetCommand@2
  displayName: 'NuGet restore'
  inputs:
    restoreSolution: '[Redacted]_V2.sln'
    verbosityRestore: Quiet
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    projects: '**/*.csproj'
    verbosityRestore: Quiet
- task: UseDotNet@2
  inputs:
    version: 3.1.x
  displayName: 'Use dotNet 3.1'
- task: SonarCloudPrepare@2
  inputs:
    SonarCloud: 'SonarCloud_[Redacted]_V2_$(projectName)'
    organization: '[Redacted]-vsts'
    scannerMode: 'MSBuild'
    projectKey: '[Redacted]-vsts_[Redacted]_Web_App_[Redacted]_$(projectName_alt)'
    projectName: '[Redacted]-vsts_[Redacted]_Web_App_[Redacted]_$(projectName_alt)'
- task: CopyFiles@2
  displayName: 'Copy test.runsettings to: $(Agent.TempDirectory)'
  inputs:
    Contents: |
      **.runsettings
    TargetFolder: '$(Agent.TempDirectory)'
- task: VSBuild@1
  displayName: 'Build $(projectName)'
  inputs:
    solution: 'Source/[Redacted]_$(projectName)/[Redacted]_$(projectName).csproj'
    msbuildArgs: '/p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=$(build.stagingDirectory) /p:UseMerge=true  /p:SingleAssemblyName=AppCode /p:PublishProfile=DockerPublishProfile.pubxml /p:Verbosity=quiet 
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
    msbuildArchitecture: x64
    logProjectEvents: false
    enableDefaultLogger: false
    customVersion: $(msBuildVersion)
- task: VSBuild@1
  displayName: 'Build [Redacted]_$(projectName) Tests'
  inputs:
    solution: 'Source/[Redacted]_$(projectName)*Tests/*Tests.csproj'
    msbuildArgs: '/p:PackageLocation=$(build.stagingDirectory)\[Redacted]_$(projectName).Tests /p:UseMerge=true /p:SingleAssemblyName=AppCode /p:DeployOnBuild=True /p:DeployDefaultTarget=WebPublish /p:OutDir=$(Build.ArtifactStagingDirectory)\$(projectName)_Tests
    platform: '$(BuildPlatform)'
    configuration: '$(BuildConfiguration)'
    maximumCpuCount: true
    customVersion: $(msBuildVersion)
  continueOnError: true
  condition: eq(variables.run_tests, 'true') 
- task: VSTest@2
  displayName: '[Redacted]_$(projectName).Tests'
  inputs:
    testAssemblyVer2: |
      **\[Redacted]_$(projectName)*Tests.dll
      !**\obj\**
    searchFolder: '$(Build.ArtifactStagingDirectory)'
    resultsFolder: '$(Agent.TempDirectory)\TestResults\[Redacted]_$(projectName)'
    codeCoverageEnabled: true
    testRunTitle: '[Redacted]_$(projectName)_Tests'
    runInParallel: true
  condition: eq(variables.run_tests, 'true')
  continueOnError: True
- task: SonarCloudAnalyze@2
  displayName: 'Run Code Analysis'
- task: SonarCloudPublish@2
  displayName: 'Publish Quality Gate Result'

Hi,

Can you verify that the branch you analyzed with this pipeline is the main branch? Is it possible you’ve been analyzing a non-main branch instead and this warning is left over from before you upgraded MSBuild?

 
Ann

Hi Ann

I can confirm that after scanning main and not allowing other out of date feature branches to scan (making main the last branch to scan) the project still displays this message unfortunately.

Kind regards

Andy

Hi Andy,

Can I have the full log of that analysis?

The analysis / scanner log is what’s output from the analysis command. Hopefully, the log you provide - redacted as necessary - will include that command as well.

This guide will help you find them.

 
Thx,
Ann

Hi Ann,

I’m stuggling to get the detailed analysis put on within the pipelines. I use azure devops and I can’t get the changes brought in do the debug analysis. If I push it to main it will disrupt everyone as the debug runs take significantly longer to run.

Going to have to abandon this ticket for now I’m afraid.

Will I have problems if this issue is persisting in the future or can I leave it?

Kind regards

Andy

Hi Andy,

If you’re sure you’re running with MSBuild 16, then we can chalk this warning up as a glitch.

That said, I haven’t seen anyone else complain about a suprious MSBuild version warning. It might be worth adding a quick pipeline update to print the MSBuild version just to make sure that what you’ve specified and what you believe you’re using is actually what’s being used.

 
Ann

Hi Anne this is the best I can do. Below is some of the build output from the build pipeline:

Starting: Build api
Task         : Visual Studio build
Description  : Build with MSBuild and set the Visual Studio version property
Version      : 1.231.0
Author       : Microsoft Corporation
Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/visual-studio-build

LOOK AT THIS LINE >>>"D:\a\_tasks\VSBuild_71a9a2d3-a98a-4caa-96ab-affca411ecda\1.231.0\node_modules\azure-pipelines-tasks-msbuildhelpers\tools\vswhere.exe" -version [16.0,17.0) -latest -format json
"C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\amd64\msbuild.exe" "D:\a\1\s\Source\[Removed]_api\[Removed]_api.csproj" /nologo /nr:false /p:DeployOnBuild=true /p:WebPublishMethod=Package /p:PackageAsSingleFile=true /p:SkipInvalidConfigurations=true /p:PackageLocation=D:\a\1\a /p:UseMerge=true  /p:SingleAssemblyName=AppCode /p:PublishProfile=DockerPublishProfile.pubxml /p:Verbosity=quiet /noWarn:S1006,S1066,S107,S1075,S108,S110,S1104,S1110,S1116,S1117,S1118,S1121,S1123,S1125,S1135,S1144,S1155,S1168,S1172,S1186,S1199,S1206,S125,S1450,S1479,S1643,S1656,S1699,S1751,S1764,S1854,S1871,S1905,S1940,S2068,S2077,S2092,S2178,S2184,S2201,S2219,S2223,S2234,S2245,S2259,S2292,S2326,S2342,S2344,S2365,S2372,S2376,S2386,S2486,S2583,S2589,S2681,S2692,S2696,S2930,S2971,S2997,S3010,S3169,S3217,S3218,S3241,S3247,S3251,S3265,S3330,S3358,S3376,S3400,S3427,S3442,S3445,S3456,S3457,S3458,S3459,S3604,S3626,S3776,S3871,S3877,S3881,S3887,S3923,S3925,S3928,S3981,S4015,S4035,S4136,S4144,S4275,S4423,S445...
Build started 8/1/2024 2:12:11 PM.

Hi,

Thanks for this. I’m going to flag this for folks who know more about why that warning might be showing up.

 
Thx,
Ann

1 Like

Hi Ann

Only thing I can think of is that I’m running Visual Studio 2019 and not visual studio 2022. 2019 should be compatible with MSbuild 16. The fact the debug kicks out the correct version number suggests that I’m using the right one. If I change it to 17 it fails.

Looking long term to migrate over to VS 2022 using the Server-2022 but our codebase has some old stuff that isn’t quite ready for that yet.

Regards

Andy

1 Like

Hi Andy, sorry for the late reply!

The warning is thrown during the project build (when the analysis happens). It is triggered when the found Roslyn version is 2.x.x, which correlates to MSBuild 15.

You are using VSBuild@1 to build the project and pass 16.0 as the customVersion argument.
The documentation states

Sets a custom version of Visual Studio. Examples: 15.0 , 16.0 , 17.0 . The required version of Visual Studio must be installed in the system.

Can you check which exact version of VS/MSBuild is installed on the agent and use that version instead of 16.0? If you are using the windows-2019 agent, the version would be 16.11.

Hi Tim,

Thanks for reaching out.

I can confirm that I’m using windows-2019 - (there is a reason but can’t remember why windows-2022 won’t work with our code so still on windows 2019)

I’ve manually set the version:
image

Definitely using VSBuild@1 with the $(msbuildVersion) variable setting the msbuild version to version 16.0. I only put this in going against the default settings after being prompted by SonarCloud to do so as I thought my runs may have been running on version 15 not 16.11.

Can you offer any further advise on things I could try or should I simply ignore the warnings?

Cheers

Andy

Did you try setting it to 16.11?