尝试使用TFS Servcice时,NuGet Package丢失错误

cod*_*fun 9 msbuild tfs 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."
Run Code Online (Sandbox Code Playgroud)

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

这是我当前的构建脚本:

<?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>
Run Code Online (Sandbox Code Playgroud)

这是我的构建日志:

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
Run Code Online (Sandbox Code Playgroud)

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

Rin*_*Tom 4

正如我在链接中看到的正如我在您发布的错误消息行的

\n\n

Nuget 2.7有如下改进:

\n\n
\n

改进

\n\n

我们\xe2\x80\x99 已更新Microsoft.Bcl.Build以使用不同的方法。新版本将使用类似于NuGet\xe2\x80\x99s\n 自动导入功能的条件导入条件导入。这将始终允许项目在 Visual Studio 中加载。

\n\n

但是,Microsoft.Bcl.Build还会向您的项目添加一个目标,该目标将在生成完成后运行。此目标检查当前构建是否恢复了包,如果是,则构建失败并显示可操作的错误消息:

\n\n

包恢复错误

\n\n

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

\n\n

第二次构建将修复此错误。请注意,只有在缺少软件包的情况下才会出现此错误,因此它不像您总是需要构建两次。

\n
\n\n

然而,下面它说它不会解决构建服务器/持续集成(CI)场景,它需要一个解决方案,如以下文章摘录中指定的:

\n\n
\n

此解决方案不解决\xe2\x80\x99t 构建服务器/持续集成\n (CI) 场景。为了在构建服务器上成功使用包还原,您有两个选择:

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

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

\n

  • 构建两次对我来说不起作用:(我两次得到相同的错误:“C:\path\project.csproj”(默认目标)(4) -&gt; (EnsureBclBuildImported target) -&gt; C:\path\project。 csproj(142,5): 错误 : 此项目引用了此计算机上缺少的 NuGet 包。启用 NuGet Package Restore 来下载它们。有关详细信息,请参阅 http://go.microsoft.com/fwlink/?链接 ID=317567。` (4认同)