Azure Devops管道-使用DotNetCoreCLI @ 2指定目标框架

时间:2018-10-03 13:43:19

标签: .net-core azure-devops azure-pipelines azure-pipelines-build-task

是否可以使用Azure Devops生成管道和DotNetCoreCLI @ 2任务为ClassLibrary项目指定目标框架?还是我们必须恢复使用脚本并手动调用dotnet publish命令?

我的管道YAML中的代码段

variables:
  buildConfiguration: 'Debug'

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

从我的.csproj:

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

我正在使用here文档来完成DotNetCoreCLI@2任务,但这并不总是很好。

编辑:在构建完全失败的那一刻,我应该补充一点,因为:

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 个答案:

答案 0 :(得分:1)

可以使用DotNetCoreCLI@2属性扩展arguments任务,您可以在该属性上指定框架(以及构建配置):

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