none
Why does Visual Studio 2017 target netcoreapp when creating a new Class Library project

    Question

  • From this post on stackoverflow:

    "If you are building a library (to be consumed by another library or application), you'll target netstandard1.X"

    "If you are building an application (console, UWP, ASP.NET Core web app), you'll target netcoreapp1.0"

    However when I create new .net core class library project in Visual Studio 2017 I see this:

        <TargetFramework>netcoreapp1.0</TargetFramework>
    

    Why does a class library target netcoreapp?


    • Edited by SWheaties Sunday, February 19, 2017 10:14 PM
    Sunday, February 19, 2017 10:13 PM

Answers

  • I understand your confusion.  The term "netcoreapp" would seem to indicate that you're targeting an application, and not a library.  This is not the case.

    netcoreapp refers to a "metapackage" of dotnet core api's.  When you target netcoreapp, you're essentially saying "Give me all the .net core api's".  This would be equivalent to targeting the full framework in .net 4.x

    There are two types of libraries for .net core, libraries that target only .net core (netcoreapp libraries) and libraries that target multiple frameworks (netstandard).  If you don't intend to target more than one framework, then just use netcoreapp.  If you do intend to target more than one framework, then use a netstandard library, but netstandard libraries only have access to a subset of API's that are available in the netstandard you are targeting.

    You might ask "Why would I want to target anything other than netstandard?", and the answer is whether or not the code you want in the library needs api's that are not in netstandard.  

    • Marked as answer by SWheaties Tuesday, July 4, 2017 4:17 PM
    Monday, June 5, 2017 6:01 AM

All replies

  • Hi SWheaties,

    Welcome to the MSDN forum.

    Refer to your description, when I try to create new project and under Visual C#, there are two .net type: .NET Core, .NET Standard and both include the project type ‘Class Library’. If I created the Class Library (.NET Core) and check the *.csproj, the TargetFramework is ‘netcoreapp1.0’ just like yours. If I chose the Class Library (.NET Standard) and I found the TargetFramework in the *.csproj file is ‘netstandard1.4’ as below:

    From the above information, for Class Library (.NET Core) template, the target framework is netcoreapp1.0 and for Class Library (.NET Standard), the target framework is netstandard1.4, which looks reasonable. If you cannot find the above project template in New project windows when you try to create a new project, please open the Visual Studio Installer of VS 2017 and make sure the following two option is checked and installed.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Tuesday, February 21, 2017 3:10 AM
    Moderator
  • Hi Sara, thank you for your response.  I understand there are two different templates for library projects.  Your answer confirmed the behavior I observed but  unfortunately you did not answer my question.  The question I asked is "Why does a class library target netcoreapp?"  I am still interested to know the answer.  Hopefully you or someone on your team can shed some light.

    Thank you.

    Tuesday, February 21, 2017 2:39 PM
  • Hi  SWheaties,

    Sorry for my misunderstanding and thank you for your feedback.

    I found the opinion that you found from stackoveflow stands for VS 2015, it was posted in 2016/7/2. Create a Class Library (.NET Core) in VS 2015 and check the project.json and the target framework is netstanadard1.6 as below:

    In VS 2017, the project.json file for .net core apps be removed and this default target framework of Class Library (.NET Core) also be modified, please have a look at this blog: Announcing .NET Core, .NET Native and NuGet Updates in VS 2017 RC, we can find the smaller project file example for .NET Core app and .NET Standard library projects:

    The following example is the new, much shorter, default template for .NET Core apps. This is the final project format for .NET Core.

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

      <PropertyGroup>

        <OutputType>Exe</OutputType>

        <TargetFramework>netcoreapp1.0</TargetFramework>

      </PropertyGroup>

    </Project>

    You can change the TargetFramework value from netcoreapp1.0 to netcoreapp1.1 in order to target .NET Core 1.1. The example project above targets .NET Core 1.0.

    Best regards,

    Sara


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

    Wednesday, February 22, 2017 3:07 AM
    Moderator
  • I understand your confusion.  The term "netcoreapp" would seem to indicate that you're targeting an application, and not a library.  This is not the case.

    netcoreapp refers to a "metapackage" of dotnet core api's.  When you target netcoreapp, you're essentially saying "Give me all the .net core api's".  This would be equivalent to targeting the full framework in .net 4.x

    There are two types of libraries for .net core, libraries that target only .net core (netcoreapp libraries) and libraries that target multiple frameworks (netstandard).  If you don't intend to target more than one framework, then just use netcoreapp.  If you do intend to target more than one framework, then use a netstandard library, but netstandard libraries only have access to a subset of API's that are available in the netstandard you are targeting.

    You might ask "Why would I want to target anything other than netstandard?", and the answer is whether or not the code you want in the library needs api's that are not in netstandard.  

    • Marked as answer by SWheaties Tuesday, July 4, 2017 4:17 PM
    Monday, June 5, 2017 6:01 AM