尝试使用TFS服务时,NuGet包丢失错误

时间:2013-09-27 01:24:54

标签: tfs msbuild nuget azure-devops

我希望有人可以帮助诊断我的构建出了什么问题。我正在使用Visual Studio 2012,NuGet 2.7和& TFS服务(git)。我一直无法解决以下错误:

"C:\a\src\src\RecipeDb.Mvc\RecipeDb.Mvc.csproj (361): This project references NuGet   package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567."

我启用了包恢复功能(但我认为我听说过nuget 2.7并不重要)。无论如何,我找到了一个关于这个问题的有用的博客: Blog Article

这是我当前的构建脚本:

<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0"
         DefaultTargets="Build" 
         xmlns="http://schemas.microsoft.com/developer/msbuild/2003">

  <PropertyGroup>
    <OutDir>$(MSBuildThisFileDirectory)bin</OutDir>
    <Configuration>Release</Configuration>
    <ProjectProperties>
        OutDir=$(OutDir);
        Configuration=$(Configuration);
    </ProjectProperties>
  </PropertyGroup>

  <ItemGroup>
    <Solution Include="$(MSBuildThisFileDirectory)src\*.sln" />
  </ItemGroup>

  <Target Name="RestorePackages">
    <Exec Command="&quot;$(MSBuildThisFileDirectory)src\.nuget\NuGet.exe&quot; restore &quot;%(Solution.Identity)&quot;" />
  </Target>

  <Target Name="Clean">
    <MSBuild Targets="Clean"
             Projects="@(Solution)"
             Properties="$(ProjectProperties)" />
  </Target>

  <Target Name="Build" DependsOnTargets="RestorePackages">
    <MSBuild Targets="Build"
             Projects="@(Solution)"
             Properties="$(ProjectProperties)" />
  </Target>

  <Target Name="Rebuild" DependsOnTargets="RestorePackages">
    <MSBuild Targets="Rebuild"
             Projects="@(Solution)"
             Properties="$(ProjectProperties)" />
  </Target>

</Project>

这是我的构建日志:

Build started 9/27/2013 1:01:14 AM.
Project "C:\a\src\build.proj" on node 1 (default targets).
RestorePackages:
  "C:\a\src\src\.nuget\NuGet.exe" restore "C:\a\src\src\RecipeDb.sln"
Project "C:\a\src\build.proj" (1) is building "C:\a\src\src\RecipeDb.sln" (2) on node 1 (Build target(s)).
ValidateSolutionConfiguration:
  Building solution configuration "Release|Any CPU".
Project "C:\a\src\src\RecipeDb.sln" (2) is building "C:\a\src\src\RecipeDb.Mvc\RecipeDb.Mvc.csproj" (3) on node 1 (default targets).
C:\a\src\src\RecipeDb.Mvc\RecipeDb.Mvc.csproj(361,5): error : This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.
Done Building Project "C:\a\src\src\RecipeDb.Mvc\RecipeDb.Mvc.csproj" (default targets) -- FAILED.
Project "C:\a\src\src\RecipeDb.sln" (2) is building "C:\a\src\src\RecipeDb.Mvc.Tests\RecipeDb.Mvc.Tests.csproj" (5) on node 1 (default targets).
C:\a\src\src\RecipeDb.Mvc.Tests\RecipeDb.Mvc.Tests.csproj(144,5): error : This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.
Done Building Project "C:\a\src\src\RecipeDb.Mvc.Tests\RecipeDb.Mvc.Tests.csproj" (default targets) -- FAILED.
Done Building Project "C:\a\src\src\RecipeDb.sln" (Build target(s)) -- FAILED.
Done Building Project "C:\a\src\build.proj" (default targets) -- FAILED.

Build FAILED.

"C:\a\src\build.proj" (default target) (1) ->
"C:\a\src\src\RecipeDb.sln" (Build target) (2) ->
"C:\a\src\src\RecipeDb.Mvc\RecipeDb.Mvc.csproj" (default target) (3) ->
(EnsureBclBuildImported target) -> 
  C:\a\src\src\RecipeDb.M
vc\RecipeDb.Mvc.csproj(361,5): error : This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.


"C:\a\src\build.proj" (default target) (1) ->
"C:\a\src\src\RecipeDb.sln" (Build target) (2) ->
"C:\a\src\src\RecipeDb.Mvc.Tests\RecipeDb.Mvc.Tests.csproj" (default target) (5) ->
  C:\a\src\src\RecipeDb.Mvc.Tests\RecipeDb.Mvc.Tests.csproj(144,5): error : This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567.

    0 Warning(s)
    2 Error(s)

Time Elapsed 00:00:09.21

所以我复制了他的构建日志,只是更改了nuget.exe所在的路径。 Nuget.exe命令似乎正在运行,但显然它没有下载软件包。当然在本地构建工作正常(即使我删除了packages目录。

2 个答案:

答案 0 :(得分:4)

正如我在您发布的错误消息行中的link中看到的那样:

Nuget 2.7的改进如下:

  

改进

     

我们已更新 Microsoft.Bcl.Build 以使用其他方法。该   新版本将使用类似于NuGet’s automatic import feature does的条件导入。这将始终允许项目   在Visual Studio中加载。

     

但是, Microsoft.Bcl.Build 还会为您的项目添加目标   将在构建完成后运行。该目标检查是否   当前构建还原包,如果是这样,则使用   可操作的错误消息:

     

Package Restore Error

     

构建恢复了NuGet包。再次构建项目以包括   这些包在构建中。有关更多信息,请参阅   http://go.microsoft.com/fwlink/?LinkID=317568

     

第二次构建将修复此错误。请注意这一点   错误只会在包丢失时出现,所以它不像你   总是要建两次。

但是,在下面它表示它不会解决构建服务器/持续集成(CI)方案,它需要一个解决方案,如以下摘录中所述:

  

此解决方案不涉及构建服务器/持续集成   (CI)场景。为了成功使用包恢复   构建服务器,您有两个选择:

     
      
  1. 签入.targets文件。
  2.   
  3. 在构建项目/解决方案之前,显式运行NuGet包还原。
  4.   

希望你所面临的问题也只是因为这个问题。

答案 1 :(得分:1)

对我来说,对Microsoft.Bcl.Build和BeforeTargets =“BeforeBuild”的引用导致了问题。当Microsoft.Bcl.Build作为依赖项添加到Azure Nuget包时添加了此项。 尝试检查项目文件并将其删除。

 <Import Project="..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets" Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" />
  <Target Name="EnsureBclBuildImported" BeforeTargets="BeforeBuild" Condition="'$(BclBuildImported)' == ''">
    <Error Condition="!Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=317567." HelpKeyword="BCLBUILD2001" />
    <Error Condition="Exists('..\packages\Microsoft.Bcl.Build.1.0.14\tools\Microsoft.Bcl.Build.targets')" Text="The build restored NuGet packages. Build the project again to include these packages in the build. For more information, see http://go.microsoft.com/fwlink/?LinkID=317568." HelpKeyword="BCLBUILD2002" />
  </Target>