JLo
JLo

Reputation: 3157

Azure Devops Pipeline - Specify Target Framework with DotNetCoreCLI@2

Is it possible to specify the target framework for a ClassLibrary project using Azure Devops Build Pipelines and the DotNetCoreCLI@2 task? Or do we have to revert to using a script and manually calling the dotnet publish command?

A snippet from my pipeline YAML

variables:
  buildConfiguration: 'Debug'

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish' 
    publishWebProjects: false # Required when command == Publish
    projects: 'TestProject/Test/Test.csproj'
    configuration: '$(BuildConfiguration)'

And from my .csproj:

  <PropertyGroup>
    <TargetFrameworks>netcoreapp2.1;net45</TargetFrameworks>
  </PropertyGroup>

I'm using the documentation here for the DotNetCoreCLI@2 task but it's not always great.

EDIT: I should add that at the moment the Build completely fails because:

The 'Publish' target is not supported without specifying a target framework. 
The current project targets multiple frameworks, please specify the framework 
for the published application. 

Upvotes: 6

Views: 6848

Answers (1)

Herman Cordes
Herman Cordes

Reputation: 4976

The DotNetCoreCLI@2 task could be extended with the arguments property, on which you could specify the framework (as well as the build configuration):

steps:
- task: DotNetCoreCLI@2
  inputs:
    command: 'publish' 
    publishWebProjects: false # Required when command == Publish
    projects: 'TestProject/Test/Test.csproj'
    arguments: '--configuration $(BuildConfiguration) --framework netcoreapp2.1'

Upvotes: 6

Related Questions