Nuget restore in TFS restores packages to different directory

烈酒焚心 提交于 2021-02-09 09:20:50

问题


I placed packages.config and nuget.config to my root folder.

When I run nuget restore on my dev machine, packages is restored into root/packages folder as described in nuget.config.

However, when I add Nuget Installer build step to my TFS2015 build definition, the packages are restored to ../Nuget/Packages, which is outside my root folder. I have a problem referencing the restored nuget packages in next build steps then.

  1. Why nuget restore behaves differently on build server?
  2. How to fix it?

nuget.config:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <config>
    <add key="repositoryPath" value="Packages" />
  </config>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <packageSourceCredentials />
</configuration>

log from NuGet restore build step:

Set workingFolder to default: C:\Builds\Agent\tasks\NuGetInstaller\0.1.18
Executing the powershell script: C:\Builds\Agent\tasks\NuGetInstaller\0.1.18\NuGetInstaller.ps1
Saving to C:\Windows\Agent\_work\2\NuGet\newNuGet.config
C:\Builds\Agent\agent\worker\tools\NuGet.exe restore "C:\Windows\Agent\_work\2\s\packages.config"  -NonInteractive -configfile "C:\Windows\Agent\_work\2\NuGet\newNuGet.config"
MSBuild auto-detection: using msbuild version '14.0' from 'C:\Program Files (x86)\MSBuild\14.0\bin'.
All packages listed in packages.config are already installed.

回答1:


You can override the packages directory from the commandline as well, that will probably be easier, as you can pass in the value using the pre-defined variables in the build:

Nuget Arguments: -PackagesDirectory "$(Build.SourcesDirectory)\Packages"



回答2:


According to the note in "Destination directory" in the Advanced option if you don't specify a folder it'll choose one for you which is probably not what you want, so just put $(Build.SourcesDirectory) there.




回答3:


About the "Path to Solution" parameter in Nuget Installer step, you need to give a path of a solution file.

If you don't have a solution and want to restore the page to the path "C:\Windows\Agent_work\2\s". In the Nuget.config file, change the repositoryPath like:

<config>
    <add key="repositoryPath" value="../s/Packages" />
</config>

But in your local environment, you need to change back to value="Packages".



来源:https://stackoverflow.com/questions/39450425/nuget-restore-in-tfs-restores-packages-to-different-directory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!