在.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”。
答案 0 :(得分: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),因此请确保在需要时进行更改。