未使用 TFS 还原 NuGet 包

NuGet Packages not being restored with TFS

我 运行 遇到了一些 NuGet 包在 TFS 构建定义中的 msbuild 过程中未恢复的问题。

我的解决方案中总共有九个 NuGet 包,我可以看到九个包中的七个已从包文件夹中恢复,但是另外两个从未恢复或什至未尝试恢复。这些包列在 packages.config 中,相应的文件夹存在于构建目录中。

我已经尝试添加此 MS document 中提到的额外 NuGet 恢复,并且我已经尝试 运行 手动 NuGet 命令但没有成功。

其他详细信息:

packages.config 的内容:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="AWSSDK.Core" version="3.3.15" targetFramework="net40" requireReinstallation="true" />
  <package id="AWSSDK.DynamoDBv2" version="3.3.4.14" targetFramework="net40" requireReinstallation="true" />
  <package id="Microsoft.Bcl" version="1.1.10" targetFramework="net40" requireReinstallation="true" />
  <package id="Microsoft.Bcl.Async" version="1.0.168" targetFramework="net40" />
  <package id="Microsoft.Bcl.Build" version="1.0.14" targetFramework="net40" />
  <package id="RestSharp" version="105.2.3" targetFramework="net40" requireReinstallation="true" />
  <package id="StackExchange.Redis" version="1.1.603" targetFramework="net40" requireReinstallation="true" />
  <package id="Twilio" version="4.7.2" targetFramework="net40" />
  <package id="Twilio.Lookups" version="1.1.0" targetFramework="net40" />
</packages>

来自 TFS 输出:

> Build started 6/29/2017 11:51:47 PM.
>      1>Project "B:\site_agent\_workd978bf9\Site\Site.sln" on node 1 (default targets).
>      1>ValidateSolutionConfiguration:
>          Building solution configuration "Debug|Any CPU". B:\site_agent\_workd978bf9\Site\site.metaproj(0,0): Warning MSB3268:
> The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the
> currently targeted framework. ".NETFramework,Version=v4.5". To resolve
> this problem, either remove the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> or retarget your application to a framework version which contains
> "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>      1>Project "B:\site_agent\_workd978bf9\Site\Site.sln" (1) is building "B:\site_agent\_workd978bf9\Site\site.metaproj" (2) on node
> 1 (default targets).
>      2>B:\site_agent\_workd978bf9\Site\site.metaproj : warning MSB3268: The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the
> currently targeted framework. ".NETFramework,Version=v4.5". To resolve
> this problem, either remove the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> or retarget your application to a framework version which contains
> "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
> B:\site_agent\_workd978bf9\Site\site.metaproj(0,0): Warning MSB3268:
> The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Threading.Tasks, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be
> resolved in the currently targeted framework.
> ".NETFramework,Version=v4.5". To resolve this problem, either remove
> the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> or retarget your application to a framework version which contains
> "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>      2>B:\site_agent\_workd978bf9\Site\site.metaproj : warning MSB3268: The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Threading.Tasks, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be
> resolved in the currently targeted framework.
> ".NETFramework,Version=v4.5". To resolve this problem, either remove
> the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.dll"
> or retarget your application to a framework version which contains
> "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
> B:\site_agent\_workd978bf9\Site\site.metaproj(0,0): Warning MSB3268:
> The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Threading.Tasks, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be
> resolved in the currently targeted framework.
> ".NETFramework,Version=v4.5". To resolve this problem, either remove
> the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> or retarget your application to a framework version which contains
> "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>      2>B:\site_agent\_workd978bf9\Site\site.metaproj : warning MSB3268: The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Threading.Tasks, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be
> resolved in the currently targeted framework.
> ".NETFramework,Version=v4.5". To resolve this problem, either remove
> the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> or retarget your application to a framework version which contains
> "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
> B:\site_agent\_workd978bf9\Site\site.metaproj(0,0): Warning MSB3268:
> The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the
> currently targeted framework. ".NETFramework,Version=v4.5". To resolve
> this problem, either remove the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> or retarget your application to a framework version which contains
> "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>      2>B:\site_agent\_workd978bf9\Site\site.metaproj : warning MSB3268: The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the
> currently targeted framework. ".NETFramework,Version=v4.5". To resolve
> this problem, either remove the reference
> "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.dll"
> or retarget your application to a framework version which contains
> "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
> B:\site_agent\_workd978bf9\Site\site.metaproj(0,0): Warning MSB3268:
> The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the
> currently targeted framework. ".NETFramework,Version=v4.5". To resolve
> this problem, either remove the reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> or retarget your application to a framework version which contains
> "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>      2>B:\site_agent\_workd978bf9\Site\site.metaproj : warning MSB3268: The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a" which could not be resolved in the
> currently targeted framework. ".NETFramework,Version=v4.5". To resolve
> this problem, either remove the reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> or retarget your application to a framework version which contains
> "System.Runtime, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
> B:\site_agent\_workd978bf9\Site\site.metaproj(0,0): Warning MSB3268:
> The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Threading.Tasks, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be
> resolved in the currently targeted framework.
> ".NETFramework,Version=v4.5". To resolve this problem, either remove
> the reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> or retarget your application to a framework version which contains
> "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>      2>B:\site_agent\_workd978bf9\Site\site.metaproj : warning MSB3268: The primary reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> could not be resolved because it has an indirect dependency on the
> framework assembly "System.Threading.Tasks, Version=4.0.0.0,
> Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" which could not be
> resolved in the currently targeted framework.
> ".NETFramework,Version=v4.5". To resolve this problem, either remove
> the reference
> "B:\site_agent\_workd978bf9\Site\packages\StackExchange.Redis.1.1.603\lib\net40\StackExchange.Redis.dll"
> or retarget your application to a framework version which contains
> "System.Threading.Tasks, Version=4.0.0.0, Culture=neutral,
> PublicKeyToken=b03f5f7f11d50a3a".
>          Copying file from "B:\site_agent\_workd978bf9\Site\site\Bin\AjaxControlToolkit.dll" to
> "site\Bin\AjaxControlToolkit.dll".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll"
> to "site\Bin\Microsoft.Threading.Tasks.Extensions.Desktop.dll".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.Async.1.0.168\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.xml"
> to "site\Bin\Microsoft.Threading.Tasks.Extensions.Desktop.xml".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.dll"
> to "site\Bin\System.IO.dll".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.1.1.10\lib\net40\System.IO.xml"
> to "site\Bin\System.IO.xml".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Threading.Tasks.dll"
> to "site\Bin\System.Threading.Tasks.dll".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Microsoft.Bcl.1.1.10\lib\net40\System.Threading.Tasks.xml"
> to "site\Bin\System.Threading.Tasks.xml".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Twilio.4.7.2\lib.5\Twilio.Api.dll"
> to "site\Bin\Twilio.Api.dll".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Twilio.4.7.2\lib.5\Twilio.Api.pdb"
> to "site\Bin\Twilio.Api.pdb".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Twilio.4.7.2\lib.5\Twilio.Api.xml"
> to "site\Bin\Twilio.Api.xml".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Twilio.Lookups.1.1.0\lib.5\Twilio.Lookups.dll"
> to "site\Bin\Twilio.Lookups.dll".
>          Copying file from "B:\site_agent\_workd978bf9\Site\packages\Twilio.Lookups.1.1.0\lib.5\Twilio.Lookups.pdb"
> to "site\Bin\Twilio.Lookups.pdb".
>          C:\Windows\Microsoft.NET\Framework\v4.0.30319\aspnet_compiler.exe -v
> /localhost_55535 -p site\ -u -f

如果可以通过 TFS 恢复其他包 build.You 可以尝试只恢复两个特定的包而不是九个。

造成这种情况的原因可能是有人在某个时候不小心检查了项目中的 packages 文件夹,因此似乎来自本地 Nuget 文件夹的内容只是从项目中的 packages 文件夹中复制出来。

如果是,请从 TFS 中删除 packages 文件夹,然后重试。

似乎解决方案中没有项目文件,除非您将 .refresh 文件添加到 bin 文件夹,否则它不会自动从包目录中恢复 dll。一旦我这样做了,在调用 msbuild 开始编译之前,所有包 dll 都被从包目录中的各自文件夹中复制出来,以解决 bin 文件夹的问题。

解决方案总结:

  • 将bin文件夹中的.refresh文件添加到TFS
  • 确保包文件夹及其内容已签入 TFS
  • 不要将bin文件夹中的实际dll添加到TFS
  • 将 TFS 构建步骤设置为还原 NuGet 包。
  • 确保您在网站代码
  • 的根目录中有一个packages.config