3
votes

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?

enter image description here

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.
3

3 Answers

4
votes

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
votes

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.

enter image description here

0
votes

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".