首页 > 解决方案 > Azure DevOps dotnet build 找不到恢复的 nuget 包

问题描述

我在使用 Azure DevOps 时遇到了一个奇怪的问题,它dotnet restore可以成功还原 nuget 包,但dotnet build由于找不到包而失败。

这是我的管道中的步骤,以及每个步骤的一些输出

  1. dotnet restore

在这一步中,我专门将 Destination 设置为packagesroot 中的文件夹,以便我可以验证包是否实际存储。此外,由于我使用的是私有 nuget 存储库,因此我指定了 NuGet.config 文件和凭据。

  1. ls && ls packages

我想确保软件包已恢复,因此我添加了此步骤。从输出中,我可以看到来自 nuget repo 和我的私人 repo 的包都在那里

  1. dotnet build

我在这一步出错(并不总是。这一步偶尔会成功,有时在我更新一些管道配置之后)。在这一步中,错误说

The type or namespace name 'Migrations' does not exist in the namespace 'Microsoft.EntityFrameworkCore' (are you missing an assembly reference?)

对于这一步,我还尝试将 PowerShell 与命令一起使用dotnet build Booking.Server.csproj -c Release --no-restore --source ..\packages,但我得到了同样的错误。

============================================

此外,我还检查了我的 csproj 文件,没有从本地路径引用任何包。

有人可以帮忙吗?

谢谢你。

============================================== 更新yaml文件

pool:
  name: Azure Pipelines
steps:
- task: DotNetCoreCLI@2
  displayName: 'dotnet restore'
  inputs:
    command: restore
    feedsToUse: config
    nugetConfigPath: Booking.Server/NuGet.config
    externalFeedCredentials: 'GitLab Nuget Repository'
    restoreDirectory: packages
    verbosityRestore: Diagnostic

- powershell: |
   ls
   ls packages
   ls packages/booking.shared
   
  displayName: 'Check pakcages'

- task: DotNetCoreCLI@2
  displayName: 'dotnet build'
  inputs:
    projects: Booking.Server
    arguments: '-c Release --no-restore --source ..\packages'
    workingDirectory: Booking.Server
  enabled: false

- powershell: |
   ls
   ls ..
   ls ../packages
   dotnet build Booking.Server.csproj -c Release --no-restore --source ..\packages --verbosity diag
  workingDirectory: Booking.Server
  displayName: Build

标签: azure-devops

解决方案


此问题的可能原因是您的路径指向不正确的包文件夹,尤其是文件夹和子文件夹之间的混淆。你可以参考这个博客


推荐阅读