【问题标题】:This project references NuGet package(s) that are missing on this computer. The missing file is ..\packages\NUnit.3.10.1\build\NUnit.props此项目引用此计算机上缺少的 NuGet 包。缺少的文件是 ..\packages\NUnit.3.10.1\build\NUnit.props
【发布时间】:2018-09-30 21:24:45
【问题描述】:

我在 Azure DevOps 站点上的 Azure Pipeline 的构建阶段遇到错误。具体来说,它抱怨的包是:

2018-09-30T20:35:07.6022998Z
==============================================================================
2018-09-30T20:35:08.4023740Z [command]C:\Windows\system32\chcp.com 65001
2018-09-30T20:35:08.4106228Z Active code page: 65001
2018-09-30T20:35:08.4688610Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\ClassService.Tests\WebAPITests.csproj --configuration release
2018-09-30T20:35:08.7564734Z Microsoft (R) Build Engine version 15.8.166+gd4e8d81a88 for .NET Core
2018-09-30T20:35:08.7565155Z Copyright (C) Microsoft Corporation. All rights reserved.
2018-09-30T20:35:08.7565308Z 
2018-09-30T20:35:09.2187455Z   Nothing to do. None of the projects specified contain packages to restore.
2018-09-30T20:35:09.2600797Z D:\a\1\s\ClassService.Tests\WebAPITests.csproj(60,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\NUnit.3.10.1\build\NUnit.props.
2018-09-30T20:35:09.2684158Z 
2018-09-30T20:35:09.2685014Z Build FAILED.
2018-09-30T20:35:09.2685593Z 
2018-09-30T20:35:09.2685883Z D:\a\1\s\ClassService.Tests\WebAPITests.csproj(60,5): error : This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is ..\packages\NUnit.3.10.1\build\NUnit.props.
2018-09-30T20:35:09.2685950Z     0 Warning(s)
2018-09-30T20:35:09.2686808Z     1 Error(s)
2018-09-30T20:35:09.2686892Z 
2018-09-30T20:35:09.2687550Z Time Elapsed 00:00:00.45
2018-09-30T20:35:09.3022976Z ##[error]Error: C:\Program Files\dotnet\dotnet.exe failed with return code: 1
2018-09-30T20:35:09.3036637Z [command]"C:\Program Files\dotnet\dotnet.exe" build D:\a\1\s\DanceWorksStudio.MobileAppService\DanceWorksStudio.MobileAppService.csproj --configuration release

我看过类似的问题,解决方案是执行 Nuget 还原,但它们通常指的是本地计算机或 Visual Studio 安装不是 Visual Studio Team Services(Azure DevOps 的旧名称)。强>

在这种情况下,计算机是 Azure DevOps 环境中的托管 2017 代理,我看不到如何在那里执行 Nuget 还原作业。

但是,在日志文件的前面部分,我确实看到了对构建代理安装所需 Nunit Nuget 包的位置的引用:

2018-09-30T20:34:18.9378894Z        Using "RestoreTask" task from assembly "C:\Program Files\dotnet\sdk\2.1.400\NuGet.Build.Tasks.dll".
2018-09-30T20:34:18.9379005Z        Task "RestoreTask"
2018-09-30T20:34:18.9379127Z          (in) RestoreGraphItems Count '19'
2018-09-30T20:34:18.9379258Z          (in) RestoreDisableParallel 'False'
2018-09-30T20:34:18.9379370Z          (in) RestoreNoCache 'True'
2018-09-30T20:34:18.9379483Z          (in) RestoreIgnoreFailedSources 'False'
2018-09-30T20:34:18.9379610Z          (in) RestoreRecursive 'True'
2018-09-30T20:34:18.9379721Z          (in) RestoreForce 'False'
2018-09-30T20:34:18.9379834Z          (in) HideWarningsAndErrors 'False'
2018-09-30T20:34:19.0149316Z          Running restore with 2 concurrent jobs.    
2018-09-30T20:34:19.0239478Z          Reading project file D:\a\1\s\DanceWorksStudio.MobileAppService\DanceWorksStudio.MobileAppService.csproj.
2018-09-30T20:34:19.0621933Z          Restoring packages for D:\a\1\s\DanceWorksStudio.MobileAppService\DanceWorksStudio.MobileAppService.csproj...


2018-09-30T20:34:20.1980374Z            GET https://api.nuget.org/v3-flatcontainer/nunit/index.json
2018-09-30T20:34:20.2168394Z            GET https://api.nuget.org/v3-flatcontainer/nunit3testadapter/index.json
2018-09-30T20:34:28.8022324Z            GET https://api.nuget.org/v3-flatcontainer/nunit/3.10.1/nunit.3.10.1.nupkg


2018-09-30T20:34:39.7126978Z          Acquiring lock for the installation of NUnit3TestAdapter 3.10.0
2018-09-30T20:34:39.7127033Z          Acquired lock for the installation of NUnit3TestAdapter 3.10.0
2018-09-30T20:34:39.7127104Z          Installing NUnit3TestAdapter 3.10.0.

2018-09-30T20:34:39.7946703Z          Acquiring lock for the installation of NUnit 3.10.1
2018-09-30T20:34:39.7947844Z          Acquiring lock for the installation of Microsoft.AspNetCore.Http.Abstractions 1.0.3
2018-09-30T20:34:39.7950455Z          Acquired lock for the installation of NUnit 3.10.1
2018-09-30T20:34:39.7950672Z          Installing NUnit 3.10.1.

2018-09-30T20:34:43.5285313Z          Completed installation of NUnit3TestAdapter 3.10.0

2018-09-30T20:34:46.7897372Z          Completed installation of NUnit 3.10.1

【问题讨论】:

  • 您需要在构建之前运行dotnet restore 命令才能安装所有必需的软件包
  • 您找到解决方案了吗?我遇到了同样的问题。
  • 有什么帮助吗?也遇到了同样的情况

标签: azure-devops nunit azure-pipelines-release-pipeline azure-pipelines-build-task


【解决方案1】:

这是一个已知的 Nuget 问题

Look here

解决方案是,在您的测试项目的 .csproj 文件中,通常在底部,您会找到一个部分

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\NUnit.3.12.0\build\NUnit.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\NUnit.3.12.0\build\NUnit.props'))" />
  </Target>

删除该部分。

【讨论】:

  • 我今天在一个全新的项目中遇到了这个错误,这为我解决了这个问题,所以显然一年多后这仍然是一个问题。
  • 无需删除整个部分;仅指向“指向那两个曾经所在的路径”,如下罗德回答
【解决方案2】:

不管怎样,我通过删除 Target 标签中的错误标签解决了这个问题。这是我最初在 .csproj 文件中的内容:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', 'packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
    <Error Condition="!Exists('packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', 'packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
</Target>

我看了看,意识到在我移动项目之前,!Exists('packages\EntityFramework.6.4.4... 的两条线指向了它们曾经所在的位置。所以,我删除了它们。现在我有了这个:

<Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">
    <PropertyGroup>
      <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>
    </PropertyGroup>
    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.props'))" />
    <Error Condition="!Exists('..\packages\EntityFramework.6.4.4\build\EntityFramework.targets')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\EntityFramework.6.4.4\build\EntityFramework.targets'))" />
</Target>

这消除了 Azure DevOps Services Pipeline 中的错误。它现在构建没有错误。

【讨论】:

  • 这是解决方案;无需删除整个部分;只有“指向这两个曾经所在的位置”的条目
【解决方案3】:

确保在管道“Build”步骤中选中“Restore NuGet Packages”选项:

【讨论】:

  • 我不认为这是正确的。如果单击“还原 NuGet 包”行旁边的“i”图标,您会看到 Microsoft 已注明 This option is deprecated. To restore NuGet packages, add a NuGet Tool Installer task before the build. 此选项没有影响。
猜你喜欢
  • 1970-01-01
  • 2014-05-19
  • 2017-07-03
  • 1970-01-01
  • 2020-01-12
  • 1970-01-01
  • 2018-02-13
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多