dotnet build not able to find nuget package in custom source while Visual Studio manage it

44 Views Asked by At

In a big .Net Solution, we are using a lot of nugets. We have three nuget sources:

  1. nuget.org
  2. Our azure dev artifact repository with a custom babelFor package(compiled with our license)
  3. A custom DevExpress repository with a specific token.

In Visual Studio, everything worked, I even cleared the nuget packages, rebuild, everything is being restore properly.

But if I run(for code analysis purpose):

dotnet build Solution/MySolution.sln --no-incremental

I receive an error that it doesn't manage to find the package for babel:

D:\VS1\XXX\YYY.csproj : error NU1101: Unable to find package Babel.Obfuscator. No packages exist with this id in source(s): DevExpress, DevExpress 19.1 Local, DevExpress 19.2 Local, DevExpress 20.2 Local, DevExpress 21.1 Local, DevExpress 21.2 Local, DevExpress 22.1 Local, DevExpress 22.2 Local, Microsoft Visual Studio Offline
 Packages, nuget.org [D:\VS1\XXX\MySolution.sln]

My packages are properly configured:

enter image description here

But it seems it doesn't try to use the Azure Devop artifact repository(Babel3)(which will require some sort of authentication).

So I'm guessing that it wasn't able to authenticate? How can I provide such authentication to dotnet build?

EDIT Apparently, I've a nuget.config file at the same place than my .sln file:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    <add key="Babel3" value="https://pkgs.dev.azure.com/XXXX/_packaging/Babel3/nuget/v3/index.json" />
    <add key="Devexpress" value="https://nuget.devexpress.com/YYYY/api" />
  </packageSources>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <config>
    <add key="repositoryPath" value="packages\" />
    <add key="globalPackagesFolder" value="packages\" />
  </config>
</configuration>

I'm just wondering if the issue could be that my SLN file is not at the root repository, and that I'm doing a dotnet build Solution/MySolution.sln

EDIT 2

If i try to run:

dotnet restore Solution/MySolution.sln --configfile Solution/nuget.config

I do get an error:

C:\Program Files\dotnet\sdk\8.0.100\NuGet.targets(156,5): error :   Response status code does not indicate success: 401 (Unauthorized). [D:\VS1\Solution\MySolution.sln]

How can I provide some identity/token when doing restore?

1

There are 1 best solutions below

8
DavidG On

That Nuget config is for Visual Studio, it doesn't not necessarily get used by the dotnet command line. I find the safest way to do this is to include a nuget.config file with your solution. That way it is source controlled and everyone get the same setup when they clone your project. Simply create the file and drop it in the root of your solution, for example:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <clear />
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="Babel3" value="https://pkgs.dev.azure.com/....../nuget/v3/index.json" />
    <add key="DevExpress" value="https://nuget.devexpress.com/....." />
  </packageSources>
</configuration>

See here for more ways to configure the package sources: https://learn.microsoft.com/en-us/nuget/consume-packages/configuring-nuget-behavior