2

在我们的 .NET Web API 项目中,我们尝试在 Azure DevOps 中构建 API 项目并将工件发布到具有以下管道任务的文件夹:

- task: DotNetCoreCLI@2
  displayName: Publish web API artifact
  inputs:
    command: publish
    publishWebProjects: false
    arguments: '$(Build.SourcesDirectory)\XYZ.Research.API\XYZ.Research.API.csproj --configuration $(BuildConfiguration) --output testpath'
    zipAfterPublish: true
    modifyOutputPath: true

但我不确定工件保存在哪个文件夹中。以下是此步骤的日志:

2020-07-31T12:04:23.6282186Z ##[section]Starting: Publish web API artifact
2020-07-31T12:04:23.6590490Z ==============================================================================
2020-07-31T12:04:23.6591051Z Task         : .NET Core
2020-07-31T12:04:23.6591393Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2020-07-31T12:04:23.6591740Z Version      : 2.172.2
2020-07-31T12:04:23.6591974Z Author       : Microsoft Corporation
2020-07-31T12:04:23.6592357Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2020-07-31T12:04:23.6592942Z ==============================================================================
2020-07-31T12:04:25.5581194Z [command]C:\windows\system32\chcp.com 65001
2020-07-31T12:04:25.5581889Z Active code page: 65001
2020-07-31T12:04:25.5583746Z Info: .NET Core SDK/runtime 2.2 and 3.0 are now End of Life(EOL) and have been removed from all hosted agents. If you're using these SDK/runtimes on hosted agents, kindly upgrade to newer versions which are not EOL, or else use UseDotNet task to install the required version.
2020-07-31T12:04:25.5588792Z [command]C:\hostedtoolcache\windows\dotnet\dotnet.exe publish d:\a\1\s\XYZ.Research.API\XYZ.Research.API.csproj --configuration Release --output testpath
.....
 some warning message ignored
.....
2020-07-31T12:04:38.0843543Z   XYZ.Research.API -> d:\a\1\s\XYZ.Research.API\bin\Release\netcoreapp3.0\XYZ.Research.API.dll
2020-07-31T12:04:38.9127845Z   XYZ.Research.API -> d:\a\1\s\testpath\
2020-07-31T12:04:46.0295716Z Info: Azure Pipelines hosted agents have been updated to contain .Net Core 3.x (3.1) SDK/Runtime along with 2.1. Unless you have locked down a SDK version for your project(s), 3.x SDK might be picked up which might have breaking behavior as compared to previous versions. 
2020-07-31T12:04:46.0296632Z Some commonly encountered changes are: 
2020-07-31T12:04:46.0297619Z If you're using `Publish` command with -o or --Output argument, you will see that the output folder is now being created at root directory rather than Project File's directory. To learn about more such changes and troubleshoot, refer here: https://docs.microsoft.com/en-us/azure/devops/pipelines/tasks/build/dotnet-core-cli?view=azure-devops#troubleshooting
2020-07-31T12:04:46.0442329Z ##[section]Finishing: Publish web API artifact

因为我们将在下一步(部署)中需要文件位置,所以我尝试了

d:\a\1\s\testpath\XYZ.Reserch.API.zip
d:\a\1\s\testpath\XYZ.Reserch.API\XYZ.Reserch.API.zip

但这些位置都没有工件文件。

以前有人见过这个问题吗?任何帮助,将不胜感激。

- - - - - - - - - - 更新 - - - - - - - - - - - - - - - -

正如@Source Code 所建议的那样,我使用了任务“PowerShell@2”,发现工件文件实际上位于“D:\a\1\s\testpath\testpath.zip”中。这意味着在 $(Build.SourceDirectory) 中创建了“testpath”子文件夹,并且工件文件也重命名为“test.zip”。

4

1 回答 1

1

我建议您在 DotNetCoreCLI@2 任务之后添加一个 PowerShell/Bash/Cmd 任务,并使用“ls”命令运行一个内联脚本,该命令应该为您列出结果中的所有项目。这将允许您查看任务完成后的实际情况。

如果在 Windows 代理上:

- task: PowerShell@2
  displayName: List Files Post Publish
  inputs:
    targetType: inline
    script: Get-ChildItem

如果在 Linux 或 Mac 上

- task: Bash@3
  displayName: List Files Post Publish
  inputs:
    targetType: inline
    script: ls

此外,我注意到您正在通过 arguments 参数提供您的 csproj 文件。有一个名为 projects 的参数应该用于此目的。您也可以考虑使用工件暂存目录作为输出目录。任务如下所示:

- task: DotNetCoreCLI@2
  displayName: Publish web API artifact
  inputs:
    command: publish
    projects: '$(Build.SourcesDirectory)\XYZ.Research.API\XYZ.Research.API.csproj'
    publishWebProjects: false
    arguments: '--configuration $(BuildConfiguration) --output $(Build.ArtifactStagingDirectory)'
    zipAfterPublish: true
    modifyOutputPath: true

需要注意的一件重要事情是,如果您确实更改了输出目录,请确保更改 PowerShell 或 Bash 任务的工作目录,以便输出正确目录的内容。它默认为 $(Build.SourcesDirectory),因此请确保在需要时进行更改。

于 2020-07-31T19:03:08.470 回答