Creating a class library in visual studio code

15,452

The best way to do it is from the console, since you are using the latest supported templates this way. VSCode also has an integrated terminal you can use for this.

$ dotnet new lib -o MyLib
$ dotnet new sln #assuming there is no .sln file yet. if there is, skip this
$ dotnet sln add MyLib/MyLib.csproj
$ cd MyConsoleApp
$ dotnet add reference ../MyLib/MyLib.csproj

If you need different frameworks, you can use the -f argument:

$ dotnet new lib -o MyLib -f netcoreapp2.0

or manually change the <TargetFramework> element inside the generated .csproj file.

Share:
15,452

Related videos on Youtube

Volkan Akın Paşa
Author by

Volkan Akın Paşa

https://www.linkedin.com/in/akinvolkan/

Updated on September 14, 2022

Comments

  • Volkan Akın Paşa
    Volkan Akın Paşa over 1 year

    It might be a silly question, Let's say I don't have a Windows OS, have a Linux. I have created a .Net core console app, also want to create a class library and reference it in console app. I can't find if i am able to do it also couldn't find a sample on Microsoft .Net core page. Is there an extension in vs code? Or isn't it possible with it? If i am mistaken could you please guide me?

  • Victor.Uduak
    Victor.Uduak about 6 years
    This works perfectly however, it create a netstandard2.0 class library, how can i create a .net core class library
  • Martin Ullrich
    Martin Ullrich about 6 years
    edited the answer to accommodate framework selection
  • user3256944 salutes Monica
    user3256944 salutes Monica over 4 years
    I found that in Visual Studio Code v1.39.2 you have to use dotnet new classlib -o MyLib
  • Kiechlus
    Kiechlus about 2 years
    There is a very useful VSCode extension called .NET Core Add Reference, it gives a GUI