简体   繁体   English

为NuGet Package Restore指定用于构建服务器的NuGet源?

[英]Specify NuGet sources for build server to use with NuGet Package Restore?

I'm using NuGet Package Restore. 我正在使用NuGet Package Restore。 I want to specify custom sources during a TFS build server process. 我想在TFS构建服务器进程中指定自定义源。

The NuGet.targets file in the hidden '.nuget' folder says that you can either specify sources repositories, or that it will fall back to the NuGet.config in %APPDATA%\\NuGet\\NuGet.config. 隐藏的“.nuget”文件夹中的NuGet.targets文件表明您可以指定源存储库,也可以回退到%APPDATA%\\ NuGet \\ NuGet.config中的NuGet.config。

There is however a NuGet.config in the hidden '.nuget' folder as well. 但是在隐藏的'.nuget'文件夹中也有一个NuGet.config。 I assumed that if you did not specify sources repositories in NuGet.targets that it would fall back to the NuGet.config in the hidden '.nuget' folder. 我假设如果您没有在NuGet.targets中指定源存储库,那么它将回退到隐藏的“.nuget”文件夹中的NuGet.config。 This doesn't seem to be the case. 似乎并非如此。

Any ideas? 有任何想法吗?

With the current version of NuGet it's possible to specify custom repositories in the solution's NuGet.config file and enable package restore during a build. 使用当前版本的NuGet,可以在解决方案的NuGet.config文件中指定自定义存储库,并在构建期间启用包还原。 Having this NuGet.config file allowed us to automatically restore packages from internal repository under a TFS build without any other actions in the build definition: 拥有此NuGet.config文件允许我们在TFS构建下自动从内部存储库恢复软件包,而构建定义中没有任何其他操作:

<configuration>
  <solution>
    <add key="disableSourceControlIntegration" value="true" />
  </solution>

  <packageSources>
    <add key="Internal" value="http://MyInternalRepository/nuget" />
  </packageSources>

  <packageRestore>
    <add key="enabled" value="True" />
  </packageRestore>

</configuration>

Note: TFS2013's default Build Process Templates already implements NuGet Package Restore workflow without any special configuration as stated here: http://docs.nuget.org/docs/reference/package-restore-with-team-build 注意:TFS2013的默认构建过程模板已经实现了NuGet Package Restore工作流程,没有任何特殊配置,如下所述: http ://docs.nuget.org/docs/reference/package-restore-with-team-build

If you enable package restore, you'll find a NuGet.targets MSBuild file in the $(SolutionDir)\\.nuget folder. 如果启用包还原,您将在$(SolutionDir)\\。nuget文件夹中找到NuGet.targets MSBuild文件。

You can set the package sources by modifying the <PackageSources>""</PackageSources> element. 您可以通过修改<PackageSources>“”</ PackageSources>元素来设置包源。

Example: 例:

<!-- Package sources used to restore packages. By default will used the registered sources under %APPDATA%\NuGet\NuGet.Config -->
<PackageSources>"http://packages.nuget.org/api/v2/;http://myget.org/F/myfeed/"</PackageSources>

According to pranavkm, one of the NuGet devs, at the time of this writing NuGet Package Restore will not use the NuGet.config in the hidden '.nuget' folder for sources. 根据pranavkm,其中一个NuGet开发人员,在撰写本文时,NuGet Package Restore将不会在隐藏的“.nuget”文件夹中使用NuGet.config作为源代码。 It's only used at the moment for a solution specific setting (to ignore source control bindings). 它仅用于特定于解决方案的设置(忽略源控件绑定)。 He says it is on the radar for the NuGet team to leverage all aspects of NuGet.config but that it keeps getting bumped in priority. 他表示,NuGet团队可以利用NuGet.config的所有方面,但它不断受到优先考虑。

Another option is to add sources to a machine-wide (not user-specific) nuget config on the build server. 另一种选择是将源添加到构建服务器上的机器范围(非用户特定)nuget配置。

https://stackoverflow.com/a/27569020/374837 https://stackoverflow.com/a/27569020/374837

in tfs build 2017 when you use the NuGet Restore task version 1.* you can select the NuGet.Config file to use during the build. 在使用NuGet Restore任务版本1时,在tfs build 2017中。*您可以选择在构建期间使用的NuGet.Config文件。 See image below NuGet Restore Task 请参见NuGet Restore Task下面的图片

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

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