Search code examples
nugetdotnet-cli

After I add NuGet.Core package to my csproj as PackageReference, I have no any effect


After I add NuGet.Core package to my csproj as PackageReference, I have no any effect. Next I describe reproduction steps and my project folder content. My question: am I doing something wrong way or it is a dotnet cli bug? I registered an issue and will be track both - this question and the issue.

Steps to reproduce:

  1. dotnet new console
  2. Change TargetFramework in csproj file to net461
  3. dotnet add package NuGet.Core
  4. Add using NuGet to Program.cs (this namespace is exists in NuGet.Core Assembly, I checked)
  5. dotnet restore
  6. dotnet build

Result: an error "The type or namespace name 'NuGet' could not be found".

Full content of my project dir:

nuget-tree.csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net461</TargetFramework>
  </PropertyGroup>
  <ItemGroup>
    <PackageReference Include="NuGet.Core" Version="2.14.0" />
  </ItemGroup>
</Project>

Program.cs:

using System;
using NuGet;

namespace nuget_tree
{
    class Program
    {
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
        }
    }
}

.NET CLI Tools Version: I'm tried on both: 1.0.4 and 2.0.0-preview2-25407-01


Solution

  • I figured out that problem is not in dotnet CLI, but in nuget. I do following:

    1. Created a Console Application in Visual Studio 2015
    2. In Package Manager Console: PM> Install-Package Microsoft.Web.Xdt -Version 2.1.0
    3. PM> Install-Package NuGet.Core -Version 2.13.1

    That is worked fine. But if I installed latest version of NuGet.Core then in packages dir in NuGet.Core subfolder there is no lib folder with assembly. And so I can't reference it in project. That is all seems weird. Then I decided to clear nuget cache. And this solves my problem. After cache was cleared I can create a new project and successfully use latest NuGet.Core.

    To clear cache I used:

    • nuget locals all -list - list the local caches
    • nuget locals all -clear - clear all caches