How to add nuget package for offline tfs build task

50 Views Asked by At

I have an TFS build server without internet access. There is a build definition with Nuget Restore step. It's configured as I understand to take package from Destination directory folder:

enter image description here

At least all old packages is at this folder.

I have to add some new packages, but when I add it to this folder build process doesn't find them:

2024-03-25T01:17:13.1908678Z Restoring NuGet package System.Text.Json.5.0.0.
2024-03-25T01:17:13.1908678Z Restoring NuGet package System.Text.Encodings.Web.5.0.0.
2024-03-25T01:17:13.1918682Z Restoring NuGet package System.Runtime.CompilerServices.Unsafe.5.0.0.
2024-03-25T01:17:13.1928680Z Restoring NuGet package System.Buffers.4.5.1.
2024-03-25T01:17:13.2258701Z Missing $(NuGetRestorePath)\.nuget\packages\system.text.json\5.0.0\system.text.json.nuspec
2024-03-25T01:17:13.2258701Z Missing $(NuGetRestorePath)\.nuget\packages\system.buffers\4.5.1\system.buffers.nuspec
2024-03-25T01:17:13.2268678Z Missing $(NuGetRestorePath)\.nuget\packages\microsoft.bcl.asyncinterfaces\5.0.0\microsoft.bcl.asyncinterfaces.nuspec
2024-03-25T01:17:13.2268678Z Missing $(NuGetRestorePath)\.nuget\packages\system.numerics.vectors\4.5.0\system.numerics.vectors.nuspec
2024-03-25T01:17:13.2278699Z Missing $(NuGetRestorePath)\.nuget\packages\system.text.encodings.web\5.0.0\system.text.encodings.web.nuspec
2024-03-25T01:17:13.2288692Z Missing $(NuGetRestorePath)\.nuget\packages\system.runtime.compilerservices.unsafe\5.0.0\system.runtime.compilerservices.unsafe.nuspec
2024-03-25T01:17:13.2308680Z Missing $(NuGetRestorePath)\.nuget\packages\system.memory\4.5.4\system.memory.nuspec
2024-03-25T01:17:13.2318684Z Restoring NuGet package System.Threading.Tasks.Extensions.4.5.4.
2024-03-25T01:17:13.2318684Z Missing $(NuGetRestorePath)\.nuget\packages\system.threading.tasks.extensions\4.5.4\system.threading.tasks.extensions.nuspec
2024-03-25T01:19:19.3462514Z WARNING: Unable to find version '4.5.0' of package 'System.Numerics.Vectors'.
2024-03-25T01:19:19.3462514Z   $(NuGetRestorePath)\.nuget\packages\: Package 'System.Numerics.Vectors.4.5.0' is not found on source '$(NuGetRestorePath)\.nuget\packages\'.
2024-03-25T01:19:19.3462514Z   https://api.nuget.org/v3/index.json: Unable to load the service index for source https://api.nuget.org/v3/index.json.
2024-03-25T01:19:19.3462514Z   An error occurred while sending the request.
2024-03-25T01:19:19.3462514Z   Unable to connect to the remote server
2024-03-25T01:19:19.3462514Z   A connection attempt failed because the connected party did not properly respond after a period of time, or established connection failed because connected host has failed to respond 13.107.246.67:443
2024-03-25T01:19:19.3462514Z 

How I must to add packages at this case? Maybe I must to register it anywhere? Or .nuspec file is necessary? If so how I can make it?

2

There are 2 best solutions below

0
Daugawpils On

Yes very likely .nuspec file is necessary.

As solution I copy packages from my local machine C:\Users.nuget\packages\ to TFS server $(NuGetRestorePath).nuget\packages\

0
wade zhou - MSFT On

The Destination directory in nuget restore task is NOT the package source, it's the folder where the packages are installed.

enter image description here

As per your error, the pacakges are missing understand path $(NuGetRestorePath)\.nuget\packages\, so what you done is directly copy the packages into the folder.

For restore from local, actually you can use nuget.config. specify local source feed as sample below, put the config in the project folder.

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="localsource" value="path/to/local/packages" />
  </packageSources>
</configuration>

in nuget restore task, you can specify the nuget.config as source.

enter image description here

The packages will be installed to the destination directory specified(c:\check):

enter image description here

If you don't specify Destination directory, the packages will be restored into a packages/ folder alongside the selected solution, package.config, or project.json.

Please check the doc NuGetCommand@2 for more details.