Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a class library in visual studio code

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?

like image 578
Volkan Akın Paşa Avatar asked Sep 30 '17 15:09

Volkan Akın Paşa


People also ask

How do I create a class library code in Visual Studio?

Start Visual Studio Code. In the Open Folder dialog, create a ClassLibraryProjects folder and click Select Folder (Open on macOS). Open the Terminal in Visual Studio Code by selecting View > Terminal from the main menu. The Terminal opens with the command prompt in the ClassLibraryProjects folder.

What is class library in Visual Studio?

A class library is a collection of class definitions contained in a . dll or .exe file. In order to use the class library, you must first add a reference to the library (see "How to add references to your Visual Studio Project").

How do I add a class library to an existing project?

4) right click your solution file and click Add --> Existing Project --> go to your folder of class library and select project file. 5)once project is added to the solution, you need to add reference to your window application. 7)select solution and check your class library project. and press OK.


1 Answers

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.

like image 128
Martin Ullrich Avatar answered Sep 18 '22 05:09

Martin Ullrich