30

I can not see the Class Library(.NET) option on Add a New Project window in Visual Studio 16.8.1. How can I create a Class Library (.NET) project? (Not .Net Core or .Net Framework)

Tolga Cakir
  • 725
  • 1
  • 7
  • 13
  • 11
    .NET 5 is .NET *Core* 5. Create a new .NET Core library and set the target framework to 5 – Panagiotis Kanavos Nov 17 '20 at 11:31
  • 4
    Create a new .NET Core class library, and change `` to `net5.0` in the csproj. .NET 5 is just rebranded .NET Core. I imagine the templates will catch up at some point. – canton7 Nov 17 '20 at 11:32
  • 2
    Any class library you create that targets `net5.0` can only be used by .NET 5 and above though, not even .NET Core 3.1. If you want to use that library with 3.1 you should target .NET Standard 2.1 – Panagiotis Kanavos Nov 17 '20 at 11:33
  • 1
    Libraries usually target the lowest acceptable version, not the highest, so that they are usable in more situations. – Dialecticus Nov 17 '20 at 11:37
  • 4
    @Dialecticus that's an over-simplification of a complex area; there are costs to targeting older frameworks, and I don't just mean the code compromises due to missing features - I mean things like "has anyone actually tested it on (older framework)?". There are many good reasons to limit libraries to more *recent* frameworks. If I was starting a library from scratch, I'd probably target net5.0 until there was a good reason to multi-target, at which time I might consider adding netcoreapp3.1; anything lower: would need serious consideration – Marc Gravell Nov 18 '20 at 08:08
  • @MarcGravell: I think there's significant merit to limiting to the latest *LTS* version. I'd personally probably start a new library with netstandard2.1, unless I needed anything from either a more recent version or from netcoreapp3.1. – Jon Skeet Nov 18 '20 at 08:17
  • @JonSkeet that's a topic we could happily discuss for hours over some drinks in a non-Covid world :) my next two questions would be: "OK, so what frameworks other than .NET Core 3.1 implement .NET Standard 2.1?" and "and have you *actually tested* on that[/those] framework[s]?". There's also another side benefit of significantly simplifying the dependency tree - you can lose a *lot* of package refs by targeting the framework rather than the API standard. I agree re LTS though: https://twitter.com/marcgravell/status/1327304774291779585 – Marc Gravell Nov 18 '20 at 08:24
  • @MarcGravell: Yup, let's grab those drinks when we can. May well be around the time .NET 6 comes out anyway. (For now, I need to keep targeting netstandard20 and net461 anyway... customers...) – Jon Skeet Nov 18 '20 at 08:30
  • I have the same issue. I see .NET Core, .NET Standard, .NET Framework but nothing that indicates .NET 5 - it would be nice if you could filter by version. – thargan Jan 05 '21 at 20:07
  • [.NET 5 not available in Visual Studio 2019](https://stackoverflow.com/questions/60843091/net-5-not-available-in-visual-studio-2019) and [Tutorial: Create a .NET class library using Visual Studio](https://learn.microsoft.com/fr-fr/dotnet/core/tutorials/library-with-visual-studio) –  Jan 16 '21 at 11:00

4 Answers4

23

In Visual Studio 2019, I believe it needs to be 16.8+, you can enable the preview feature Show all .NET Core templates in the New project dialog.

enter image description here

Go Tools -> Options -> Environment -> Preview Features -> Show all .NET Core templates in the New project dialog (Requires Restart)

Then close Visual Studio and reopen it. Now from the new project dialog there should be a Class Library with a C# in the tags.

enter image description here

From here, click Next. Fill out where you want it to be made and what to call it as you normally would.

enter image description here

Then click Next again. This will bring you to a new screen that has a drop down for the Target Framework.

enter image description here

Set this to .NET 5.0 and click Create. This creates a .NET 5.0 class library and opens it in the IDE.

Dan
  • 7,286
  • 6
  • 49
  • 114
  • 1
    Great answer. Just to add on to this, an updated version of Visual Studio is neccessary, as you also pointed out. https://developercommunity.visualstudio.com/t/target-frameworks-missing/1208780 – thesystem Jun 23 '21 at 21:51
19

If the project templates are still giving you .NET Core 3.1 as the highest option, and the project properties options aren't allowing what you want - it isn't a problem: simply right-click on the project in Solution Explorer and select "Edit Project File", to edit the .csproj, and you can change the target framework - for example, from

<TargetFramework>netcoreapp3.1</TargetFramework>

to

<TargetFramework>net5.0</TargetFramework>

to target .NET 5, or

<TargetFrameworks>netcoreapp3.1;net5.0</TargetFrameworks>

to multi-target.

Marc Gravell
  • 1,026,079
  • 266
  • 2,566
  • 2,900
  • 7
    I like how the current generation seems to have no idea why it's called *Visual* Studio. I don't know if Microsoft sees having to edit the project file by hand as an advancement. But it makes no sense to me. – Jonathan Wood Feb 19 '21 at 16:15
  • @JonathanWood and most changes *can* be made via the UI; I'm not concerned if some niche things can't - and honestly, there shouldn't be any "magic" - it is worth taking the time to know what the UI is doing – Marc Gravell Feb 19 '21 at 16:41
  • 3
    The more you can learn, the better. But the "visual" relates to productivity. I should be able to create a project that uses the latest framework from Microsoft without manually editing the project file. I mean, otherwise, why have menus? Just give us a big command windows and we'll type everything in. That would eliminate almost all the "magic." – Jonathan Wood Feb 19 '21 at 17:10
  • 1
    @JonathanWood: To me, since Visual C++ 6.0, it was about double clicking a button in the dialog editor and getting to the OnButton_Click-code - and then not questioning "Visual" again :D – Sebastian Mach Oct 18 '21 at 13:39
5

You can try the following steps to create a Class Library project based on .NET 5.0.

First, please download the .NET 5.0 SDK from Download .NET 5.0 and install it.

Second, please use the following command to create the project.

dotnet new Classlib -n Testlib

enter image description here

Third, please find the specific path and open the project Testlib.csproj.

Finally, you can see a class library based on .NET 5.0.

enter image description here

Jack J Jun
  • 5,633
  • 1
  • 9
  • 27
3

The easiest way is to create .NET Core library and then simply change Target framework in project properties. .NET 5.0 is available!

enter image description here

But note, if you create .NET Framework library, the options to change to .NET Core or .NET 5.0 will not be there.

It seems like Visual Studio is treating .NET 5.0 as the latest version of .NET Core. It's in the same bin.

This is with Visual Studio 2019 version 16.8.4

zar
  • 11,361
  • 14
  • 96
  • 178