0

I've been using this SO answer and this Powershell script to transform .NET config files.

The gist of the script is that it downloads a local version of nuget.exe, then uses this to download NuGet packages which will be used for the XDT transformations.

My problem is that when it invokes a line to download a NuGet package I'm told that the package cannot be found. For example...

Unable to find version '3.1.0' of package 'Microsoft.Web.Xdt'.

...even though nuget.org clearly states that this is valid - link. I've tried it with other packages and their publicly-stated versions, and receive the same message.

Another point to be aware of is that we have our own private NuGet feed. When I run the Powershell script it will also attempt to search that feed, which I don't want it to do, so I have added a nuget.config file in the same directory as the Powershell script (I've also tried it in the same directory as the local nuget.exe) in which I have disabled our custom NuGet source...

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
  </packageSources>
  <disabledPackageSources>
    <add key="DevOps" value="true" />
  </disabledPackageSources>
  <packageRestore>
    <add key="enabled" value="True" />
    <add key="automatic" value="True" />
  </packageRestore>
  <bindingRedirects>
    <add key="skip" value="False" />
  </bindingRedirects>
  <packageManagement>
    <add key="format" value="0" />
    <add key="disabled" value="False" />
  </packageManagement>
</configuration>

Other than that <disabledPackageSources /> section the rest of this nuget.config was copied from my machine-level nuget.config.

Can anyone explain why this local instance of nuget.exe is unable to find any packages from nuget.org?

awj
  • 7,482
  • 10
  • 66
  • 120
  • With the provided nuget.exe from _http://nuget.org/nuget.exe_, can you give us the output in CLI cmd of `nuget source` and check if `nuget list` outputs anything ? – Zilog80 Jun 01 '21 at 15:24
  • (The _http://nuget.org/nuget.exe_ is not signed, i suggest you to use a source providing a signed executable and check automatically the signature with your local `signtool.exe`) – Zilog80 Jun 01 '21 at 15:25
  • 1
    Aha! `.\nuget.exe source` shows "https://www.nuget.org/api/v2/ [Disabled]", which puzzles me because that doesn't correspond with the content of the nuget.config file sitting alongside nuget.exe. `.\nuget.exe list` returns "No packages found." – awj Jun 02 '21 at 06:39
  • I guess you'll have to specify explicitly the nuget.config path with `-ConfigFile` in the script. Check also [the documentation](https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior), the provided `nuget.exe` could be older than 3.4 and then look for a `.nuget` subdirectories for its config file. – Zilog80 Jun 02 '21 at 15:28

0 Answers0