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

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

是否可以使用 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>

我正在使用文档 hereDotNetCoreCLI@2任务,但并不总是很好。

编辑:我应该补充一点,目前 Build 完全失败,因为:
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. 

最佳答案

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'

关于.net-core - Azure Devops 管道 - 使用 DotNetCoreCLI@2 指定目标框架,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52628444/

相关文章:

azure-devops - 从模板将环境变量设置为 azure Devops 管道步骤

azure - Azure YAML 管道中版本号的共享计数器

Azure 开发运营 : Pipeline for all branches but master

.net - 控制 dotnet pack 项目引用的版本约束

azure - 如何在使用 Azure cloudshell 克隆 Web 应用程序时修复 'conflicts with an already existing hostname'

azure - 使用 ARM 模板自动创建 Azure DevOps 组织

azure-devops - Visual Studio Online 自动生成版本号增量和程序集修补

c# - 使用字符串作为 Id 测试详细信息操作

.net-core - dotnet 发布输出文件夹?

c# - .Net Core 正则表达式、命名组、嵌套组、反向引用和惰性限定符