Sameer
Sameer

Reputation: 137

Where to define files required by many projects in visual studio?

Let's say I have 5 or 6 projects in my solution. There is a file called fileCopyHelper.cs that basically copies files from one folder to another. I need this file for a lot of projects in the solution and I don't want to keep redefining it in every project? How do I do it?

I tried adding a .cs file to the solution and Visual studio grouped it into Solution items folder. However I'm unable to access the classes defined in this file in my projects because Solution items is just a folder, not a project, so I can't add a namespace reference from other projects.

Upvotes: 0

Views: 35

Answers (1)

Grant Winney
Grant Winney

Reputation: 66439

Add a new project to your solution, and select the class library type. This gives you a single place to add code that will be shared.

Reference the new project in whatever other projects in your solution need access to the code.

Your setup might look something like this, where the fileCopyHelper class is party of ClassLibrary1, which is then referenced and used in the main ConsoleApp1 application:

enter image description here

Upvotes: 2

Related Questions