4
votes

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. 
1
Hello @JLo ; a side question : Did you try to set buildConfiguration: 'Release' ? Because when I do this, the build is using 'Debug'Stef Heyenrath

1 Answers

3
votes

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'