0

Here's my csproj targeting net6.0:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <ImplicitUsings>enable</ImplicitUsings>
    <Nullable>enable</Nullable>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="HtmlAgilityPack" Version="1.11.45" />
    <PackageReference Include="System.Drawing.Common" Version="6.0.0" />
  </ItemGroup>
</Project>

It needs two libraries HtmlAgilityPack and System.Drawing.Common. Both are .Net6.0 compatible (according to nuget). Locally I have .NET SDK installed for net6.0:

dotnet --info
.NET SDK (reflecting any global.json):
 Version:   6.0.400
 Commit:    7771abd614

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19043
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.400\

global.json file:
  Not found

Host:
  Version:      6.0.8
  Architecture: x64
  Commit:       55fb7ef977

.NET SDKs installed:
  6.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Yet, when I run dotnet restore I get this error:

  Determining projects to restore...
C:\Repos\test\test.csproj : error NU1100: Unable to resolve 'HtmlAgilityPack (>= 1.11.45)' for 'net6.0'.
C:\Repos\test\test.csproj : error NU1100: Unable to resolve 'System.Drawing.Common (>= 6.0.0)' for 'net6.0'.
  Failed to restore C:\Repos\test\test.csproj (in 104 ms).

What am I missing here? I think dotnet restore should complete without errors.

rfg
  • 1,331
  • 1
  • 8
  • 24
  • Was not able to repro. Is it possible you have nuget.config file in the solution somewhere? Or disabled some nuget sources? – Guru Stron Sep 05 '22 at 18:05
  • 1
    Try `dotnet restore -v detailed`. It should then show what it's trying to do. – PMF Sep 05 '22 at 19:01
  • https://learn.microsoft.com/en-us/nuget/consume-packages/install-use-packages-visual-studio#package-sources – Hans Passant Sep 05 '22 at 19:43

1 Answers1

1

Per @PMF's suggestion.

  1. Ran dotnet restore -v detailed, got the same error.
  2. From the output found global nuget.config file (C:\Users\admin\AppData\Roaming\NuGet\NuGet.Config).
  3. Checked the config:
<?xml version="1.0"?>
<configuration>
  <packageSources>
  </packageSources>
</configuration>
  1. Added nuget:
<?xml version="1.0"?>
<configuration>
  <packageSources>
    <add key="NuGet" value="https://api.nuget.org/v3/index.json" />
  </packageSources>
</configuration>

After that dotnet restore worked as expected.

rfg
  • 1,331
  • 1
  • 8
  • 24