简体   繁体   English

Nuget自动还原 - 为TFS Build指定自定义存储库

[英]Nuget Automatic Restore - Specifying custom repositories for TFS Build

I am attempting to migrate to nuget's new Automatic Package Restore. 我正在尝试迁移到nuget的新自动包恢复。 Whilst it works fine on my own machine (packages are restored), builds performed as a TFS Build on the build server do not build, complaining that they cannot find the various dlls (that should have been downloaded as part of the restore). 虽然它在我自己的机器上工作正常(包被恢复),但是在构建服务器上作为TFS Build执行的构建不构建,抱怨他们找不到各种dll(应该已经作为恢复的一部分下载)。

I have created a nuget.config in my solution folder, as specified here: 我在我的解决方案文件夹中创建了一个nuget.config,如下所示:

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

I have also tried putting this nuget.config file next to the nuget.exe file in TFS, in the hope that it would be used, but to no avail. 我也尝试将这个nuget.config文件放在TFS中的nuget.exe文件旁边,希望它能被使用,但无济于事。

The nuget reference here: 这里的nuget参考:

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

states that the nuget.config in my solution folder should be picked up. 说明我的解决方案文件夹中的nuget.config应该被选中。 But it appears that it isn't. 但似乎事实并非如此。

I'm at the end of my tether. 我在我的系绳的尽头。 According to nuget, the Package Restore feature is designed specifically so that packages don't need to be checked in. However, there's scant information about how to get TFS to actually restore the packages, and what I've found does not work. 根据nuget的说法,Package Restore功能是专门设计的,因此不需要签入包。但是,关于如何让TFS实际恢复包的信息很少,而且我发现的功能不起作用。

Any help would be gratefully received. 我们将非常感激地提供任何帮助。

My nuget.config looks like this: 我的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>

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?" “TFS怎么知道如何打电话给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. 在坐下来思考这一段时间后(正如@Matt Ward正确指出的那样)我发现TFS Build无法知道nuget是否参与,因为新的“自动”包恢复消除了它的需要成为构建本身的一部分。

This question has actually been asked here: 这个问题实际上已在这里被问到:

How does TFS know about nuget? TFS如何了解nuget?

Although the accepted answer is NOT actually the correct one. 虽然接受的答案实际上并不正确。 Scroll down to probackpacker's answer, which is essentially that: 向下滚动到probackpacker的答案,基本上是这样的:

"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: 这实际上在nuget有很好的记录:

http://docs.nuget.org/docs/reference/package-restore-with-team-build 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. 但是,我忽略了它,因为a)自动包恢复的整个要点是远离基于MSBuild的过程(虽然我现在明白为什么这是不同的),和b)它似乎比我需要的更复杂。 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. 也就是说,一个澄清的声明,如“如果你正在使用自动包恢复与TFS团队建设,你必须创建一个MSBuild项目,以便调用包恢复”将有所帮助。 It's obvious once you understand what's happening - confusing when you don't. 一旦你理解了正在发生的事情就很明显 - 当你不了解时会感到困惑。 But we live and learn. 但我们生活和学习。

depending on the version of visual studio, it should just be a matter of right clicking on the solution and selecting Enable NuGet Package restore. 根据visual studio的版本,只需右键单击解决方案并选择Enable NuGet Package restore即可。 this will create a Nuget folder that contains, NuGet.exe, a NuGet.Targets file and NuGet.config. 这将创建一个Nuget文件夹,其中包含NuGet.exe,NuGet.Targets文件和NuGet.config。

you can update the targets file with a local NuGet Feed if you have one. 您可以使用本地NuGet Feed更新目标文件(如果有)。

to test locally, delete the contents of your packages folder, and ReBuild the solution, this will download the files from NuGet and your solution should build correctly. 要在本地测试,删除packages文件夹的内容,然后重新构建解决方案,这将从NuGet下载文件,您的解决方案应该正确构建。 check in the NuGet folder and files to source control, your packages should not be added to source control. 检查NuGet文件夹和文件到源代码控制,不应将您的包添加到源代码管理中。

your TFS build should now be able to restore the packages 您的TFS构建现在应该能够恢复包

NuGet Restore

Now if this is how you are set up and it still doesn't work on TFS, log onto the build server with the build account and load the solution locally, make sure the package restore works as the build account on the build machine, you may have a firewall / proxy issue, where the build server / build account can't access the Nuget.org internet site 现在,如果这是您的设置方式并且仍然无法在TFS上运行,请使用构建帐户登录构建服务器并在本地加载解决方案,确保程序包还原在构建计算机上用作构建帐户,您可能有防火墙/代理问题,其中构建服务器/构建帐户无法访问Nuget.org Internet站点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM