Azure Pipeline .NET Core Build task uses higher MSBuild version than specified in global json SDK

455 Views Asked by At

I have used "Use .Net Core" task in azure to install SDK using below global json.

{
  "sdk": {
    "version": "6.0.410",
    "rollForward": "disable",
    "allowPrerelease": false        
  }
}

But after that in the next .Net Core - "Build" command pipeline task, while building the application, it uses MSBuild version 17.7.1 instead using 17.6.8.

Earlier it was correctly picking up MS Build version 17.6.8 and this issue started few days back.

Is there a way to specify which MSBuild version to use in the .Net Core - "Build" command pipeline task? Why is it not picking the correct version related to SDK?

I have tried specifying the exact SDK version in the "Use .Net Core" task as well and specified Compatible Visual Studio version as well.

1

There are 1 best solutions below

0
On

I tried using below yaml code to run MS Build with .net version 6.0.410 and the pipeline ran successfully like below:-

YAML code:-

trigger:
- main

pool:
  vmImage: 'windows-latest'

variables:
  solution: '$(System.DefaultWorkingDirectory)/WebApplication5.sln'  # Update the path to your .sln file if needed

stages:
- stage: Build
  jobs:
  - job: Build
    steps:
    - task: UseDotNet@2
      inputs:
        packageType: 'sdk'
        version: '6.0.410'  
        installationPath: $(Agent.ToolsDirectory)/dotnet  

    - powershell: |
        
        dotnet nuget locals all --clear

        
        dotnet --version

        
        dotnet restore ${{variables.solution}}
        dotnet build ${{variables.solution}} --configuration Release
      displayName: 'Restore and Build'

    - task: UseDotNet@2
      inputs:
        packageType: 'sdk'
        version: '6.0.410'  


    - task: MSBuild@1
      inputs:
        solution: ${{variables.solution}}
        msbuildArguments: '/p:Configuration=Release'  # Adjust this as needed
        platform: 'Any CPU'  
        logProjectEvents: true
        clean: true  
      displayName: 'Build with MSBuild'

    - powershell: |
        # Run any additional tasks here
        # For example, you can publish your application or run tests
      displayName: 'Run Additional Tasks'

Output:-

enter image description here

enter image description here

global.json:-

{
  "sdk": {
    "version": "6.0.410",  
    "rollForward": "disable",
    "allowPrerelease": false        
  }
}