azure-devops - Azure Function 的 Azure 管道未找到项目
问题描述
我有一个使用 .Net Core 3.1.x 的 Azure 函数的构建管道。发布之前的所有步骤都做得很好。我可以使用脚本使发布步骤工作,但不能通过 yaml 任务。我错过了什么?
剧本(作品)
- script: dotnet publish --configuration Release .\af-process-mds-vehicle-output-to-deviation\af-process-mds-vehicle-output-to-deviation.csproj
任务(不工作)
- task: DotNetCoreCLI@2
displayName: 'Publish Project'
inputs:
command: 'publish'
configuration: 'Release'
projects: '.\af-process-mds-vehicle-output-to-deviation\af-process-mds-vehicle-output-to-deviation.csproj'
zipAfterPublish: true
它没有找到该项目。这是错误消息。
2021-10-29T05:21:44.3024816Z ##[section]Starting: dotnet publish
2021-10-29T05:21:44.3150367Z ==============================================================================
2021-10-29T05:21:44.3150726Z Task : .NET Core
2021-10-29T05:21:44.3151190Z Description : Build, test, package, or publish a dotnet application, or run a custom dotnet command
2021-10-29T05:21:44.3151475Z Version : 2.187.0
2021-10-29T05:21:44.3151733Z Author : Microsoft Corporation
2021-10-29T05:21:44.3152035Z Help : https://docs.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2021-10-29T05:21:44.3152373Z ==============================================================================
2021-10-29T05:21:44.7797987Z [command]C:\Windows\system32\chcp.com 65001
2021-10-29T05:21:44.7903026Z Active code page: 65001
2021-10-29T05:21:44.7927221Z 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.
2021-10-29T05:21:44.8938257Z ##[error]No web project was found in the repository. Web projects are identified by presence of either a web.config file, wwwroot folder in the directory, or by the usage of Microsoft.Net.Web.Sdk in your project file. You can set Publish web projects property to false (publishWebProjects: false in yml) if your project doesn't follow this convention or if you want to publish projects other than web projects.
2021-10-29T05:21:44.9001249Z Info: Azure Pipelines hosted agents have been updated and now contain .Net 5.x SDK/Runtime along with the older .Net Core version which are currently lts. Unless you have locked down a SDK version for your project(s), 5.x SDK might be picked up which might have breaking behavior as compared to previous versions. You can learn more about the breaking changes here: https://docs.microsoft.com/en-us/dotnet/core/tools/ and https://docs.microsoft.com/en-us/dotnet/core/compatibility/ . 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
2021-10-29T05:21:44.9003648Z ##[error]Project file(s) matching the specified pattern were not found.
2021-10-29T05:21:44.9182124Z ##[section]Finishing: dotnet publish
在得到答案的提示后,我得到了管道工作。这是完整的工作管道。(仍然不知道为什么它没有早点工作。)
工作管:
name : af-vehicle-sync-to-deviation
## if there is a change is the deviation folder for the main branch. Then trigger.
trigger:
branches:
include:
- main
paths:
include:
- af-process-mds-vehicle-output-to-deviation/*
pool:
vmImage: 'windows-latest'
variables:
buildConfiguration: 'Release'
SolutionPath: '**\*.sln'
stages:
- stage: Build
displayName: Build solution
jobs:
- job: Build
displayName: Build and publish solution
steps:
- checkout: self
- task: NuGetToolInstaller@1
- task: NuGetCommand@2
inputs:
restoreSolution: $(SolutionPath)
- task: UseDotNet@2
inputs:
packageType: 'sdk'
version: '3.1.x'
displayName: 'Use .NET Core SDK 3.1.x'
- task: DotNetCoreCLI@2
inputs:
command: 'build'
configuration: $(buildConfiguration)
projects: '$(SolutionPath)'
displayName: 'Build solution'
- task: DotNetCoreCLI@2
displayName: 'Publish Project'
inputs:
command: 'publish'
configuration: 'Release'
projects: '**\*.csproj'
publishWebProjects: false
zipAfterPublish: true
arguments: '--output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
- task: PublishBuildArtifacts@1
inputs:
PathtoPublish: '$(Build.ArtifactStagingDirectory)'
ArtifactName: 'drop'
publishLocation: 'Container'
解决方案
您可以使用'**/*.csproj'
,但老实说,我会做类似这个答案的事情,并添加一个脚本以在此步骤失败之前递归列出所有文件和文件夹。
假设您在此发布之前有一个恢复或构建步骤,您可以在这些之后添加它,或者就像您结帐之后的第一步一样。
您还可以检查先前步骤的日志以查看文件路径。有关执行此操作的说明可在此处获得。
$(System.DefaultWorkingDirectory)
还建议使用作为您的根,而不是.\
, 所以您将拥有'$(System.DefaultWorkingDirectory)\af-process-mds-vehicle-output-to-deviation...'
.
编辑
如果您查看构建步骤的日志,您会看到类似的条目/home/vsts/work/1/s/XXX.YYY.ZZZ/XXX.YYY.ZZZ.csproj
引用解决方案中的不同项目。默认情况下,大多数命令将在其中运行,$(System.DefaultWorkingDirectory)
这相当于/home/vsts/work/1/s/
在这种情况下,您可以将其视为存储库的根 - 这里有关于此结构的更多信息。
您遇到的错误实际上是关于缺少 Web 项目,而不是路径问题,但对于构建步骤,最佳做法是使用--output <output-directory-here>
标志将编译文件输出到特定文件夹,这样您就可以轻松发布那个文件夹。
推荐阅读
- xml - ST 转换序列化期间错误的命名空间绑定
- python-3.x - 在wireshark中解密python请求https流量
- android - 在“vivo”和“xiaomi”设备中关闭应用时收不到推送通知
- reactjs - 在严格模式树中发现了一个字符串 ref,“canvas”
- r - 在因子组中的最小值和最大值之后选择 x 条记录
- php - PHP while 循环处理速度更快,可能使用 PHP 工作者实现
- python - python中sort和sorted之间的区别以及它们的反转?
- c# - 动态 IQueryable 连接查询
- angular - 如何使用 Angular 9 获取窗口登录帐户名?
- python - 是否有一种简单的方法可以在 Python 中为 content-disposition 标头编码(unicode)文件名?