Search code examples
idevisual-studio-2022

Adding .net class library reference in Visual Studio 2022


I have a Models directory which contains a file ContactModel.cs, I want to use it in my Form1.cs file in the FormApp directory. I have been going through the similar questions asked on this, but couldn't find a solution.

This is my folder structure:

Folder structure

Right clicking on the directories shows these options:

Menu on right click


Solution

  • You're in "folder view" in your Solution Explorer, examining the file system. One of the icons at the top of the Solution Explorer allows you to "switch between available views". Use that to switch to viewing your solution instead of the folders:

    enter image description here

    When viewing the solution, right-click on the project to which you want to add a reference (in this case the FormApp project) and select Add -> Project Reference.

    From there, select the class library project in the solution that you want your application project to use (in this case the Models project).