Search code examples
visual-studionugetdependency-management.net-standard

How to I stop my NetStandard 1.0 Nuget dragging in the NetStandard.Library in a 4.7.1 project?


I have created a Net Standard project and packaged that using Nuget, using the pack command of the dotnet application.

C:\Program Files\dotnet\dotnet.exe" pack src/Acp.Framework.Essentials

This creates a NetStandard 1.0 class assembly in the following Nuget package:

NuGet Package Explorer showing reference to netstandard1.0

If I add this Nuget package in Visual Studio to a Windows Classic Desktop .Net Console application targeting 4.7.1 it drags in the NetStandard.Library 1.6.1 Nuget package and it's long list of facades. These dll's are copied to the bin folder, and it includes all the redirects in the app.config.

I don't want these facades installing (neither the Nuget references, nor copied to the output folder) and I don't want the redirects in the app.

My understanding is that with 4.7.1 you don't need the NetStandard.Library. Is my understanding correct?

Do I need to change the Nuget package to stop them being pulled in, am I doing something else wrong?

In the proj file for the consuming project I have

<Project ToolsVersion="15.0" ... />
<TargetFrameworkVersion>v4.7.1</TargetFrameworkVersion>

I have tried this in Visual Studio 2017 15.4.1 and 15.4.2.

If I reference the dll directly, or by the project instead of Nuget, it works fine


Solution

  • My understanding is that with 4.7.1 you don't need the NetStandard.Library. Is my understanding correct?

    Yes, you are right.

    The NETStandard.Library package references a set of NuGet packages that define the .NET Standard library. Like the Microsoft.AspNetCore package, the package does not contain dlls itself, but rather references a number of other packages.

    In addition, the NETStandard.Library package will typically be referenced by projects, though not by libraries. So the NETStandard library package should not be referenced by libraries. And this dependency was changed the in the version 2.0.4, you can create a project with target framework .NET Standard 2.0:

    enter image description here

    See What is the NETStandard.Library metapackage? for more detail info.

    Besides, You could disable the NETStandard.Library dependency from being included as a dependency of your NuGet package without disabling the implicit reference entirely with the following:

    <ItemGroup>
        <PackageReference Update="NETStandard.Library" PrivateAssets="all" />
    </ItemGroup>
    

    Or you can delete that dependency by NuGet Package Explorer directly.

    Hope this helps.

    Edit: Updated to include Johan B's comment, below, using PrivateAssets="all"