Azure Function 的 Azure 管道找不到项目

Azure pipeline for Azure Function does not find project

我有一个使用 .Net Core 3 的 Azure Functions 的构建管道。1.x。发布之前的所有步骤都很好。我可以通过使用脚本来获取发布步骤,但不能通过 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',但老实说,我会做类似 的事情,并添加一个脚本以在失败的这一步之前递归地列出所有文件和文件夹。

假设您在此发布之前有一个恢复或构建步骤,您可以在这些之后添加它,或者只是作为结帐之后的第一步。

您还可以检查前面步骤的日志以查看文件 path/s。有关执行此操作的说明可用 here

还建议使用 $(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/,您可以将其视为存储库的根 - 有关此结构的更多信息 here.

您遇到的错误实际上是关于缺少 Web 项目,而不是路径问题,但是对于构建步骤,最佳做法是使用 --output <output-directory-here> 标志将编译文件输出到一个特定的文件夹,这样您就可以轻松发布该文件夹。