Visual Studio: Add Item / Add as link rather than just Add

I think that the 'best practice' is to have those 'common' routines into an assembly that you can reference instead of pulling the source files into a bunch of different projects. You could add it as a pre-built assembly with "Add reference..." or by including a project for that assembly and adding a reference to the project (also done inthe "Add reference..." dialog).

This is one of those things that seems like a bit of work to set up initially (and it may be), but it generally pays off in the long run.


If you want to "reference" matrix.cs in your project, don't use Add Existing Item, create a reference ("Add Reference") to the class library or object that matrix.cs is a part of. If you don't want (or can't use) the library or object that matrix.cs is part of, then the Add Link is how you would get to it, but seriously I've never used that particular feature.

None of the developers I have ever worked with in .NET isolate their .cs files in separate folders. The only kind of segregation like that that I have seen as a practice is in MVC, where the models, views and controllers are in their own folders.


You can just use Add As Link by clicking on the little down arrow to the right of the add button from Add-->Existing Item command...

(Thanks Peter)

Whilst I realise this is not in an answer to the original question (which regards best practices), I present this answer in order to save the time of others who have been directed here by the misleading title of this question.


The "best practice" in this case, is to not fight the tool. It allows you to do what you want, but you'll get more work done and be able to focus on code if you just let the IDE organize your project for you.

I would create an empty solution project called PdMagic.Common

This will give you a file structure like

PdMagic.Common\
PdMagic.Common\PdMagic.Common.sln

then I generally add a src and libs folder (via the file system, not VS)

inside the libs folder, i would place all my third party dependencies, and the src folder would hold all of my projects

PdMagic.Common\
PdMagic.Common\PdMagic.Common.sln
PdMagic.Common\libs
PdMagic.Common\libs\nunit
PdMagic.Common\src

Next, in Visual Studio, I would right click on the Solution I just created, and click "Add -> New Project", I would specify that I wanted it created in the \src folder and call it PdMagic.Common.Math

Now my folder structure would look like this

PdMagic.Common\
PdMagic.Common\PdMagic.Common.sln
PdMagic.Common\libs
PdMagic.Common\libs\nunit
PdMagic.Common\src
PdMagic.Common\src\PdMagic.Common.Math
PdMagic.Common\src\PdMagic.Common.Math\PdMagic.Common.Math.csproj
PdMagic.Common\src\PdMagic.Common.Math\Class1.cs

Then, as you add classes to your PdMagic.Common.Math project, they will go in the folder with the project file. This is how the IDE has the opinion we should work, and I think most developers go with it because trying to get any other layout on the file system would require too much fighting with the IDE. I know it can be hard to come from a different convention, and you instinctively want the same conventions in the new environment. However, if you stick with the conventions, (right or wrong in your opinion) you'll get more done because you won't be trying to force the IDE to do things the way you think they should be done.