Azure函数的Azure管道找不到项目



我用。net Core 3.1.x构建了一个Azure函数的构建管道。出版前的所有步骤都做得很好。我可以通过使用脚本使发布步骤工作,但不能通过yaml任务。我错过了什么?

脚本(作品)

- script:  dotnet publish --configuration Release .af-process-mds-vehicle-output-to-deviationaf-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-deviationaf-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://learn.microsoft.com/azure/devops/pipelines/tasks/build/dotnet-core-cli
2021-10-29T05:21:44.3152373Z ==============================================================================
2021-10-29T05:21:44.7797987Z [command]C:Windowssystem32chcp.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://learn.microsoft.com/en-us/dotnet/core/tools/ and https://learn.microsoft.com/en-us/dotnet/core/compatibility/ . To learn about more such changes and troubleshoot, refer here: https://learn.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',但老实说,我会这样做,并添加一个脚本,在此步骤失败之前递归列出所有文件和文件夹。

假设您在此发布之前有一个还原或构建步骤,您可以将其添加在这些步骤之后,或者作为签出步骤之后的第一步。

您还可以检查前面步骤的日志以查看文件路径/s。

还建议使用$(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>标志输出编译文件到一个特定的文件夹,这样你就可以很容易地发布该文件夹。

相关内容

  • 没有找到相关文章

最新更新