1
votes

I am running Visual Studio and tried Hello World console example for dotnet core.

PS d:\test> dotnet nuget list source
Registered Sources:
  1.  Microsoft Visual Studio Offline Packages [Enabled]
      C:\Program Files (x86)\Microsoft SDKs\NuGetPackages\
  3.  Package source 1 [Enabled]
      C:\Program Files\dotnet\packs
  4.  Package source 2 [Enabled]
      C:\Program Files\dotnet\sdk\NuGetFallbackFolder

PS d:\test> dotnet --info
.NET Core SDK (reflecting any global.json):
 Version:   3.1.300
 Commit:    b2475c1295

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

Host (useful for support):
  Version: 3.1.4
  Commit:  0c2e69caa6

.NET Core SDKs installed:
  2.1.514 [C:\Program Files\dotnet\sdk]
  3.1.300 [C:\Program Files\dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.18 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.4 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

To install additional .NET Core runtimes or SDKs:
  https://aka.ms/dotnet-download

The example gives package not found error:

PS d:\test> dotnet new console --force
The template "Console Application" was created successfully.

Processing post-creation actions...
Running 'dotnet restore' on d:\test\test.csproj...
  Determining projects to restore...
d:\test\test.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.App.Ref. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, Package source, Package source 1, Package source 2
  Failed to restore d:\test\test.csproj (in 402 ms).

The package is available at: C:\Program Files\dotnet\packs\Microsoft.AspNetCore.App.Ref\3.1.3 Also, if I try changing the target framework to 2.1 everything works fine.

Default .csproj file created by dotnet command line.

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

  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.1</TargetFramework>
  </PropertyGroup>

</Project>

Is there something I missed?

EDIT: Output after running clean

PS d:\test> dotnet clean Microsoft (R) Build Engine version 16.6.0

+5ff7b0c9e for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

Build started 5/30/2020 6:01:58 PM.

Build succeeded.
    0 Warning(s)
    0 Error(s)

Time Elapsed 00:00:01.71
PS d:\test> dotnet run
d:\test\test.csproj : error NU1101: Unable to find package Microsoft.AspNetCore.App.Ref. No packages exist with this id in source(s): Microsoft Visual Studio Offline Packages, Package source, Package source 1, Package source 2

The build failed. Fix the build errors and run again.

If I just change 'netcore3.1' => 'netcore2.1' and everything works.

1
Can you post the complete csproj - vivek nuna
Please post your complete csproj code and alsobefore that, once clean the solution using clean command try building again - vinothvs
This is the complete csproj created by command 'dotnet new console' <Project Sdk="Microsoft.NET.Sdk"> <PropertyGroup> <OutputType>Exe</OutputType> <TargetFramework>netcoreapp3.1</TargetFramework> </PropertyGroup> </Project> - mangupt
Did you install .Net SDK version 3.1 ? - Majid Azarniush
I have installed both 2.1 and 3.1. "C:\Program Files\dotnet\sdk\2.1.514" "C:\Program Files\dotnet\sdk\3.1.300" - mangupt

1 Answers

0
votes

Thanks for all the suggestion.

I figured the issue. My nuget source list didn't have following, so tool never tried online for packages.

https://api.nuget.org/v3/index.json