views:

348

answers:

6

I never use "Add existing item..." feature in Visual Studio's Solution Explorer because it is confusing:

  • it seems to me the way it should work is that if you have a Customer.cs file in Models directory, that you could choose "Add existing item", it would then show you which items exist in that directory an allow you to choose one. Instead, it opens a file dialogue to some seemingly random directory on your hard drive, and I'm not sure if it is going to make a copy of that file, or use it outside the solution, etc.
  • instead, if I want to "add an existimg item", I go into windows explorer, click file, CTRL-C, click folder in solution explorer, ctrl-v, and it is clear

Do others do it differently? Am I missing something about how "add existing item" in solution explorer is supposed to work?

+1  A: 

I'm using it. I even didn't know it's possible to ctrl+c ctrl+v in solution explorer.

It's particulary handy, if you want to add something 'as link'.

Arnis L.
+1  A: 

I do use it but often I just add file as a link. That make it easier to maintain some common classes if you do not want to make full assembly out of them.

Josip Medved
When you say "link", do you mean that you add a reference to an external item (DLL, etc)?
shambleh
No. The "Open" button has an arrow next to it. Drop it down and you'll see you can add a link to a file, as well as adding the file itself.
John Saunders
A: 

As far as my experience goes using this function, it does the same copy and paste that you are describing.

shambleh
+2  A: 

Add Existing file adds the file to the project. Keeping it in the project directory is something different and making it a part of the project is something different. By making it a part of the project, its entry is made in .csproj/.vcproj/etc and then further properties can be set of this file such as specifying a custom build step etc.

And No, it doesn't create a copy of the file in your current project's directory in case of a Visual C++ project. In case of a CSharp Project, it does create a copy.

e.g., I use this when I need to add a bitmap/png file in my project which I have gotten from an external source. I just copy the file to my project directory and then use Add Existing File to add this to the project.

Aamir
+9  A: 

The folder opens where-ever you last left it...

As for using this feature; by default (Add) it does IMO the least useful thing; copy the file. But if you notice, the add button is actually a drop-down; hit the down arrow and you can add a link to the file - i.e. leave it where it is and reference it by location (Add As Link).

Marc Gravell
+1 for "didn't know that"
Edward Tanguay
Already knew it because needed to use it to link same code files in .NET and Silverlight project ... and didn't know about the <kbd><kbd></kbd> tag before : - )
chakrit
but does this mean you have files floating around on your hard drive which belong to your solution? this means that you can't just "zip the solution directory" and send it to someone else right, back it up, etc. isn't that a major disadvantage compared to just putting everything you need for a solution under the main directory?
Edward Tanguay
@Edward: Maybe it is just the way I work, but I don't tend to import classes between projects; I would reference other projects. So if I'm adding an **existing** item (rather than adding a new class etc), I'm probably adding something *related* from the same repository trunk; and so a copy isn't necessary. The most important thing is having the control over which to do, I guess.
Marc Gravell
+2  A: 

The quick and easy way to do what you are trying to do (add an existing file that already exists within the folder in your project) is:

  • At the top of the Solution Explorer window is an icon/button for "Show All Files", enable it (if it is already enabled and the file you are looking for is not shown, click "Refresh"). Note that this setting is enabled on a per project basis.
  • Right click on the file that you want to include and select "Include in Project".
Chris Shaffer