3

我正在尝试迁移到 nuget 的新自动包还原。虽然它在我自己的机器上运行良好(包已恢复),但在构建服务器上作为 TFS 构建执行的构建不会构建,抱怨他们找不到各种 dll(应该作为恢复的一部分下载)。

我在我的解决方案文件夹中创建了一个 nuget.config,如下所示:

http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html

我也试过把这个 nuget.config 文件放在 TFS 中的 nuget.exe 文件旁边,希望它会被使用,但无济于事。

这里的nuget参考:

http://docs.nuget.org/docs/reference/nuget-config-file

指出我的解决方案文件夹中的 nuget.config 应该被拾取。但似乎并非如此。

我已经走到尽头了。根据 nuget 的说法,包还原功能是专门设计的,因此不需要签入包。但是,关于如何让 TFS 实际还原包的信息很少,而且我发现的内容不起作用。

任何帮助将不胜感激。

我的 nuget.config 看起来像这样:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
    <add key="ads" value="<address to local repository>" />
  </packageSources>
</configuration>
4

2 回答 2

3

As it so often turns out, the answer is the answer to a question I didn't actually ask:

"How does TFS even know how to call nuget?"

After sitting and thinking about this for a while (and as @Matt Ward correctly points out) it occurred to me that the TFS Build has no way of knowing nuget is even involved, since the new "Automatic" package restore removes the need for it to be part of the build itself.

This question has actually been asked here:

How does TFS know about nuget?

Although the accepted answer is NOT actually the correct one. Scroll down to probackpacker's answer, which is essentially that:

"If you are using automatic package restore, you must have a build process that calls it before building your solution"

This is actually well documented at nuget:

http://docs.nuget.org/docs/reference/package-restore-with-team-build

However, I had disregarded it since a) the entire point of Automatic Package Restore is to move away from an MSBuild based process (although I do now understand why this is different), and b) it seemed more complicated than I needed. It's not. That said, a clarifying statement such as "If you are using Automatic Package Restore with TFS Team Build, you MUST create a an MSBuild project in order to call Package Restore" would have been helpful. It's obvious once you understand what's happening - confusing when you don't. But we live and learn.

于 2014-07-09T08:15:50.017 回答
-1

根据 Visual Studio 的版本,只需右键单击解决方案并选择 Enable NuGet Package restore 即可。这将创建一个 Nuget 文件夹,其中包含 NuGet.exe、一个 NuGet.Targets 文件和 NuGet.config。

如果您有本地 NuGet 源,则可以使用本地 NuGet 源更新目标文件。

要在本地进行测试,删除包文件夹的内容,然后重新构建解决方案,这将从 NuGet 下载文件,并且您的解决方案应该正确构建。将 NuGet 文件夹和文件签入源代码管理,您的包不应添加到源代码管理。

您的 TFS 构建现在应该能够恢复包

NuGet 还原

现在,如果这是您的设置方式并且它仍然无法在 TFS 上运行,请使用构建帐户登录构建服务器并在本地加载解决方案,确保包还原作为构建机器上的构建帐户工作,您可能存在防火墙/代理问题,其中构建服务器/构建帐户无法访问 Nuget.org 互联网站点

于 2014-07-08T14:24:12.447 回答