Azure 管道:不要为了运行测试而再次构建

时间:2021-05-06 10:24:10

标签: azure-devops

steps:

- task: DotNetCoreCLI@2
  displayName: dotnet build
  inputs:
    command: 'build'
    arguments: '--configuration $(BuildConfiguration)'

- task: DotNetCoreCLI@2
  displayName: dotnet test
  inputs:
    command: test
    projects: 'Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.csproj'
    arguments: '--configuration $(buildConfiguration)'

我注意到 test 步骤再次构建了解决方案,这很愚蠢,因为 解决方案已通过构建步骤构建,因此测试应仅使用已创建的 bin 目录。

能做到吗?怎么样?

1 个答案:

答案 0 :(得分:1)

默认情况下,像 test 或 pack 这样的 Dotnet 命令会构建项目。

有两种解决方案:

  1. 包括 --no-build 参数:
-task: DotNetCoreCLI@2
  displayName: dotnet test
  inputs:
    command: test
    projects: 'Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.csproj'
    arguments: '--no-build --configuration $(buildConfiguration)'
  1. 您可以对构建创建的 .dll 执行测试,如下所示:
- script: dotnet test Playtech.Neon.Privacy.TestPlaytech.Neon.Privacy.Test.dll
  workingDirectory: '<Path_To_The_Build_Directory>'
  displayName: Run Tests

您可能可以对 DotNetCoreCLI@2 任务执行相同的操作,但我没有对此进行测试。

但总体阅读documentation始终是一个好的第一步;)