Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure Devops - Targeting Multiple .NET frameworks in solution

I have setup Azure pipeline which build several projects and solutions with different .NET frameworks. Used frameworks: .NET Standard 2.1, .NET 4.7.2, .NET5, .NET Core 3.1. I use pool windows-2019 and everything works fine.

Now, I have to build new project which targets .NET 6 and has to be build first in pipeline. Because pool windows-2019 doesn't have installed .NET 6, I have to install it using UseDotNet task. But once I install .NET 6, the rest of projects build fail.

I know that older framework can be specified again using UseDotNet task, but I have problem because one solution (Solution 3 in yaml snippet) include projects using .NET 5 and .NET Core 3.1. So when I specify .NET 5 with UseDotNet task, solution build fails because .Net Core 3.1 is missing or viceversa.

Is it possible to specify two frameworks to be used before solution build? Or how this situation should be handled?

Snippet:

pool:
      vmImage: 'windows-2019'

- task: UseDotNet@2
  displayName: 'Use .NET 6 sdk'
  inputs:
    version: 6.0.x
    includePreviewVersions: true

#Project Uses only .Net 6
- task: DotNetCoreCLI@2
  displayName: 'Build ProjectUsingNet6'
  inputs:
    command: 'build'
    projects: '**\ProjectUsingNet6.sln'

#Solution uses only .NET 3.1
- task: UseDotNet@2
  displayName: 'Use .Net Core 3.1'
  inputs:
    version: '3.1.x'

- task: VSBuild@1
  displayName: ProjectUsingNet31
  inputs:
    solution: '**\SolutionTargetingNet31.sln'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
    
#Projects in solution tagerting .NET Standard 2.1, .NET 4.7.2, .NET 5, .Net Core 3.1 which fails
- task: VSBuild@1
  displayName: Solution 3
  inputs:
    solution: '**\Solution3.sln'
    platform: '$(buildPlatform)'
    configuration: '$(buildConfiguration)'
like image 205
Jakub Vojtašák Avatar asked Oct 26 '25 05:10

Jakub Vojtašák


1 Answers

Azure Devops - Targeting Multiple .NET frameworks in solution

Agree with GeralexGR. When you have multiple .NET frameworks in solution, you could use the stage for each framework, especially if your .NET frameworks are not backward compatible.

stages:
- stage: .NET 6 sdk
  jobs:
  - job:
    ...

- stage: .NET 5 sdk
  jobs:
  - job:
    ...

- stage: .NET 3.1 sdk
  jobs:
  - job:
    ...

You could check the Add stages, dependencies, & conditions for some more details.

like image 108
Leo Liu-MSFT Avatar answered Oct 28 '25 17:10

Leo Liu-MSFT



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!