Skip to content

Class Libraries

A Class Library is a project that contains types and methods used by applications. The compiled result of a class library is a Dynamic Link Library (DLL).

Creating a New Project

Creating a Class Library project follows the same steps as a Console Application, except that you will choose a different project template.

When you get to the Create a new project window, the project type you want to choose is called "Class Library (.NET Framework)". You can use the search to filter the list.

Create Class Library Project

Solution File Structure

If you navigate to the location you created the project to, you’ll find the solution directory for the project you created.

Save Directory

Warning

At this point you may have more than one Visual Studio solution stored in this location. Read the directories careful to determine the one you are looking for.

Solution Directory

Solution Directory

The solution directory contains:

  • Project Directory - You will see one directory for each project in the solution. New solutions will only contain one project and thus will have one project directory.
  • Solution File (.sln) - A file that ends with the file extension .sln. The .sln file contains information the Visual Studio environment needs to find and load the solution's associated projects and resources.

Project Directory

Project Directory

The project directory contains:

  • bin Directory - Contains binary files. These are the application or library assemblies generated during a successful project build.
  • obj Directory - Contains compiled binary files that haven't been linked yet and will later be combined to produce the assembly file stored in the bin directory.
  • Properties Directory - Contains information about the project. This information can be viewed and edited in Visual Studio.
  • MS Build File (.csproj) File - The MSBuild file for the Visual Studio project.
  • Class1.cs - This file contains a class called Class1 and is created by default because of the project template that was chosen when creating the project.

Danger

Class1 is not an appropriate name for a class. You should rename this file and the class identifier within it.

Visual Studio Solution Explorer

Solution Explorer

When the newly created class library project is loaded into Visual Studio, the Solution Explorer will contain the following:

  • Properties - This node can be ignored.
  • References - This node contains the project references to other class libraries.
  • Class1.cs - The source code file Class1.cs that contains the Class1 class.

Building the Project

Building (Compile) a Project was discussed in a previous topic.

On a successful build of a Console Application Project, the following files will be generated in the bin\Debug directory within the Project directory.

Debug Directory

The files you see in the screenshot above are:

  • Dynamic Link Library File (.dll) - The assembly file, which is the compiled version of your project.
  • Program Database File (.pdb) - The program database file that contains debugging information about the library. You can ignore this file.

Enable XML Documentation

An .xml file containing the documentation from your source code can be generated at compile time. The .xml file is not generated by default.

To enable the creation of the .xml file:

  1. Right-click the project node of the class library and choose Properties from the context menu. This will open the project properties editor.
  2. Select the Build tab (located on the left side of the project properties editor).
  3. Enable the XML documentation file option. (It is not recommended that you change the file path.)

Further Reading