Removing items from project

rbulph

Junior Contributor
Joined
Feb 17, 2003
Messages
397
If you have an item, a module or a class say, which exists in one project, and you add it to another project, how can you then remove it from the second project? If you right click on it you can exclude it from the project, which results in it still being shown, but faded out, or you can delete it, which means it will be lost from the original project. I just want to go back to the situation where it wasn't part of the second project at all. How do I do that?
 
Generally, each project has its own folder (usually within the solution's folder), although it is possible to place them both in the same folder. It is also an option to show all files, including those that are not part of a project. If you have the option enabled to display all files then an item should should appear grayed out in any projects which it is not a part but whose folder it is present in.

If the projects are in different folders and you add an item from the first project to the second, you can either add it normally, which will place a copy of the file in the second project's folder, or you can add it as a link, where it is a shortcut pointing to the original file (it will be displayed with the Windows shortcut icon).

Most likely, you have the two projects in different folders and are adding the item from one project to another normally (i.e. not a link) which means that the file will be copied. If you exclude it, it will still be present in the second project's folder, hence it is displayed grayed out. If you delete it, it should not delete the original.
 
OK, thanks. I understand. But how do you add an item as a link? I go Project/Add Item and I'm not given any option to add the item as a link, so I can't see this. I'm using Visual Studio 2005.
 
Be wary of adding items to a project as a link. Generally, a project folder can be moved as a whole. It will contain every file relevant to the project within. When you begin adding files as links you now have relative file references which means that if you move or copy the folder (for example, zipping it and uploading it), the project will cease to work. I suppose it would be reasonably acceptable to have links to files from other projects within the same solution.
 
Thanks. If I have been working on some sample code in a small project, as I often do if there's a particular problem which I want to figure out, and then want to put parts of that code into my main project, it seems that adding files temporarily as a link is a good way to do this. I can then copy and paste the code from there. I suppose I could add the whole project to the solution, but this is easier to navigate. Anyway I agree, adding links is not a very good thing to do long term.
 
Back
Top