10

我希望有人可以帮助诊断我的构建出了什么问题。我正在使用 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 没关系)。无论如何,我在以下位置找到了一个关于这个问题的有用博客: 博客文章

这是我当前的构建脚本:

<?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 命令似乎正在运行,但显然它没有下载包。当然在本地构建工作正常(即使我删除了包目录。

4

2 回答 2

4

对我来说,对 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>
于 2015-01-23T20:04:41.090 回答
4

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

Nuget 2.7 有如下改进:

改进

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

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

包还原错误

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

第二次构建将修复此错误。请注意,这个错误只会在缺少包的情况下出现,所以你不必总是构建两次。

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

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

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

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

于 2013-09-27T15:17:47.133 回答