Azure DevOps Pipeline - 使用DotNetCoreCLI@2指定目标框架

4

使用Azure Devops Build Pipelines和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>

我正在使用这里的文档来完成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. 

你好 @JLo;顺便问一下:你有尝试设置 buildConfiguration: 'Release' 吗?因为当我这样做时,构建使用的是 'Debug'。 - Stef Heyenrath
1个回答

4
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'

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接