Call or Reference c# (csharp) or vb code in your visual studio project

I see many questions like this popup on stackoverflow, or even beginner .net programmers asking this question. Many of them worded differently, but asking the same thing. “How do I reference other projects in visual studio”. You can find a worded version on MSDN or you can view the pictorial version below:

Referencing the project

You can reference the project with all the source code, etc. You can make real-time changes here and the visual studio intellisense will reflect those changes, even before compiling the other project.

You can create a whole new solution with just a class library project or you can add a class library to an existing project(silverlight will contain their own type of class library as they use a subset of the .net framework):

 

You need to reference this project:

 

If its already in your solution, just view the Projects tab and you’ll see a list of projects you can reference:

It should then be listed in your reference folder:

Referencing an assembly

You can also reference the compiled dll or any other assembly (.exe) you wish. (Which is what referencing a project actually does, it just points the reference the other other project’s build output directory). Just do as you would with referencing a project, but just browse for a the file. When referencing a built assembly, you loose debugging features (unless you want to debug the IL), but no C# or higher level language debugging is available.

Now you can reference a class, just remember to add the namespace. The referenced project’s code should be public so other assemblies can access it.