【问题标题】:##[error]Project file(s) matching the specified pattern were not found##[错误]未找到与指定模式匹配的项目文件
【发布时间】:2018-10-29 18:56:30
【问题描述】:

我在构建管道时遇到问题。

代理池托管于 VS2017

YAML 是

pool:
  vmImage: 'VS2017-Win2016'

variables:
  buildConfiguration: 'Debug'

steps:
- task: DotNetCoreInstaller@0
  displayName: 'Use .NET Core sdk 2.1.5'
  inputs:
    version: 2.1.403


- task: DotNetCoreCLI@2
  displayName: Restore
  inputs:
    command: restore

    projects: '**/Api*.csproj'


#Your build pipeline references an undefined variable named ‘Parameters.projects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971
- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.projects)'

    arguments: '--configuration $(BuildConfiguration)'


#Your build pipeline references an undefined variable named ‘Parameters.projects’. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab. See https://go.microsoft.com/fwlink/?linkid=865972
#Your build pipeline references the ‘BuildConfiguration’ variable, which you’ve selected to be settable at queue time. Create or edit the build pipeline for this YAML file, define the variable on the Variables tab, and then select the option to make it settable at queue time. See https://go.microsoft.com/fwlink/?linkid=865971

- task: DotNetCoreCLI@2
  displayName: Publish
  inputs:
    command: publish

    publishWebProjects: false

    projects: '$(Parameters.projects)'

    arguments: '--configuration $(BuildConfiguration) --output $(build.artifactstagingdirectory)'

- task: PublishBuildArtifacts@1
  displayName: 'Publish Artifact'
  inputs:
    PathtoPublish: '$(build.artifactstagingdirectory)'

构建任务运行时有如下日志

2018-10-29T18:28:43.7087338Z ##[section]Starting: Build
2018-10-29T18:28:43.7093502Z ==============================================================================
2018-10-29T18:28:43.7093580Z Task         : .NET Core
2018-10-29T18:28:43.7093785Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
2018-10-29T18:28:43.7093818Z Version      : 2.141.0
2018-10-29T18:28:43.7093864Z Author       : Microsoft Corporation
2018-10-29T18:28:43.7093895Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
2018-10-29T18:28:43.7093925Z ==============================================================================
2018-10-29T18:28:44.4833128Z [command]C:\Windows\system32\chcp.com 65001
2018-10-29T18:28:44.4926077Z Active code page: 65001
2018-10-29T18:28:45.1965225Z ##[error]Project file(s) matching the specified pattern were not found.
2018-10-29T18:28:45.2037015Z ##[section]Finishing: Build

我注意到日志指向 2.141.0,因为我正在恢复最新的 SDK 2.1.403 为什么会这样?莫非是托管的VS2017代理不支持.netcore最新版本?

[更新]

我为 Parameters.projects 添加了一个变量

但是构建任务仍然有错误。

2018-10-29T21:07:38.6774331Z ##[section]Starting: Build
2018-10-29T21:07:38.6781540Z ==============================================================================
2018-10-29T21:07:38.6781632Z Task         : .NET Core
2018-10-29T21:07:38.6781676Z Description  : Build, test, package, or publish a dotnet application, or run a custom dotnet command. For package commands, supports NuGet.org and authenticated feeds like Package Management and MyGet.
2018-10-29T21:07:38.6781762Z Version      : 2.141.0
2018-10-29T21:07:38.6781807Z Author       : Microsoft Corporation
2018-10-29T21:07:38.6781853Z Help         : [More Information](https://go.microsoft.com/fwlink/?linkid=832194)
2018-10-29T21:07:38.6781915Z ==============================================================================
2018-10-29T21:07:39.5030735Z [command]C:\Windows\system32\chcp.com 65001
2018-10-29T21:07:39.5157531Z Active code page: 65001
2018-10-29T21:07:39.5840366Z ##[error]Project file(s) matching the specified pattern were not found.
2018-10-29T21:07:39.5916864Z ##[section]Finishing: Build

【问题讨论】:

  • 您是否将值放入变量$(Parameters.projects)
  • 没有。我该怎么做?
  • 好像我错过了粘贴 YAML 来设置代理?
  • 仅在构建任务中构建失败,请看我的回答。

标签: azure-devops azure-pipelines


【解决方案1】:

张贴以防万一这对将来的任何人有帮助

我将vmImage 设置为ubuntu,设置如下:

projects: '**\*.csproj'

反斜杠把东西扔掉了,我不得不切换到以下内容:

projects: '**/*.csproj'

我从假设 Windows 的指南中复制。够微妙的,我花了一段时间才注意到?

【讨论】:

  • 感谢@jack-casey 发布此问题,我正面临与此问题相反的情况(在 Windows 上构建,但从 Linux 指南复制)
  • 在 ubuntu 中切换到反斜杠来转发 lash 对我有用。
【解决方案2】:

您需要在构建任务中定义您要构建的.csproj 文件。

在您的情况下,定义在变量 $(Parameters.projects) 中。

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '$(Parameters.projects)'

    arguments: '--configuration $(BuildConfiguration)'

您可以在 .csproj 中替换此变量(例如,**/*.csproj 用于所有子文件夹中的所有 .csproj 文件):

- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: '**/*.csproj'

    arguments: '--configuration $(BuildConfiguration)'

或者转到变量选项卡并添加Parameters.projects 变量:

【讨论】:

  • 从变量中删除“...”。 **/*.csproj 不是 '**/*.csproj'
  • 这可行,但答案不好。我需要一个特定的项目路径。
  • @DarthVader 你是什么意思?你能解释更多吗?
  • 显然不是:'D
  • @ShaykiAbramczyk 您关于删除单引号的提示对我帮助很大!我一直在 YAML 文件上部署管道,在所有路径上都使用单引号,遇到了奇怪的问题,因此在我第一次尝试后它显然应该工作时不得不进行疯狂的试验和错误尝试......我现在看到,对于我有多个路径,例如在 .NET Core CLI 构建任务中,在多行中有多个构建路径,没有必要插入引号,当引号存在时,结果实际上是意外的
【解决方案3】:

我正在尝试在 dotnet 核心中构建和发布多项目解决方案。 解决方案结构为:

sampleTest.API
      sampleTest.API.csproj
sampleTest.Data
      sampleTest.Data.csproj
sampleTest.Identity
      sampleTest.Identity.csproj
sampleTest.Web
      sampleTest.Web.csproj
sampleTest.sln

现在,我只想构建 sampleTest.API dotnet 核心项目。我只需要在构建任务中定义,项目路径如下图。

Azure Devops 中管道构建任务的 yaml 文件如下所示:

steps:
- task: DotNetCoreCLI@2
  displayName: Build
  inputs:
    projects: 'sampleTest.API/*.csproj'
    arguments: '--configuration $(BuildConfiguration)'

如果我们需要基于搜索所有“cs.proj”文件来构建 - 我们会这样做

projects: '**/*.csproj'

在 Azure Devops 中使用经典编辑器的示例构建任务如下所示:

【讨论】:

    猜你喜欢
    • 2021-03-16
    • 1970-01-01
    • 2020-11-14
    • 2020-08-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多