skip to Main Content

enter image description here

I don’t know how to add a class library here, how does it turn into this?

enter image description here

I am really lost right now since our prof did not teach much about this, I just really want to know but I am still very confused about this

3

Answers


  1. The best possible process to add a class library would be to follow the MicroSoft tutorial from the Microsoft Learn site.

    https://learn.microsoft.com/en-us/dotnet/core/tutorials/library-with-visual-studio-code?pivots=dotnet-8-0

    But in short, you will need to create a new project just for the class library that you include your class into. Make sure the program you are going to use this class library with has a reference to your new class library project.

    If you want to include a class directly in your program project, that is possible, but it will not be a separate library that you can reuse in other projects dynamically. You will have to add that code directly into other projects. Libraries are good for developing multiple applications that share a common set of class utilities that you want to ensure the code base doesn’t become redundant. If you need classes to reuse from within your main program, you may not need a library on its own.

    Login or Signup to reply.
    1. Start Visual Studio Code – Select File > Open Folder from the main menu. In the Open Folder dialog, create a ClassLibraryProjects folder and click Select Folder.
    2. Open the Terminal by selecting View > Terminal from the main menu.
    3. Create a solution – In the Terminal, enter the following command:

    dotnet new sln

    1. Create a class library project – Add a new .NET class library project named StringLibrary to the solution.
    2. In the terminal, run the following command to create the library project:

    dotnet new classlib -o StringLibrary

    (The -o or –output command specifies the location to place the generated output.)

    1. Add the library project to the solution. Run the following command:

    dotnet sln add StringLibrary/StringLibrary.csproj

    1. Check the library targets. In Explorer, open StringLibrary/StringLibrary.csproj

    Please make sure you have the .NET 8 SDK and Visual Studio Code with the C# extension installed.

    Login or Signup to reply.
  2. What you are doing is adding a class called classlibrary.cs
    If the second image is all you want then all you have to do is right click on the project and select -> Add -> Class.

    Than name it whatever you want e.g. "ClassLibrary.cs".

    Note: Class libraries are a collection of classes and namespaces in C# without any entry point method like Main, meaning it is a seperate project that you "Reference" in your main project.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search