Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing an existing source file in Visual Studio 2012

I want to add the source-code of a tutorial into an existing project, and I want the file to be copied to the project folder from the temporary file on the desktop I downloaded it to. Context clicking on the "Source Files" Folder in the Solution Explorer leads me the Add->Existing Item... menu, and I can then add the source file. However, it is NOT copied into the project folder, but stays in its original location. The project just knows about it, displays it in the Solution Explorer, and considers it part of the project.

This help page on MSDN tells me that in Visual Studio 2010, default behaviour used to consist in copying the file into the project folder, and that one could choose to Add a link instead of physically importing the file into the project directory by choosing "Add Link". However, now I always only get a link, and real physical import into the project folder seems impossible.

I could go through the File Explorer to physically import, but the Solution Explorer doesn't update the new files on the fly, and I would like to do this from within VS.

Is there a way? Is this a bug in VS 2012?

like image 538
yippy_yay Avatar asked Dec 15 '13 21:12

yippy_yay


People also ask

How do I add an existing file to Visual Studio?

You can add existing files to your project by right-clicking on the Project node and selecting Add > Add Files.... Alternatively, to add an entire folder, select Add > Add Existing Folder.... The file browser is shown. It lets you search your system for the required item to add.

How do I open an existing project in Visual Studio 2012?

Open Visual Studio. On the start window, select Open a project or solution. Visual Studio opens an instance of File Explorer, where you can browse to your solution or project, and then select it to open it.

How do I create a project from an existing source in Visual Studio?

On the File menu, select New > Project From Existing Code. Specify your project location, the directory for your source files, and the kinds of files the wizard imports into the new project. Choose Next to continue. Specifies the directory path of the new project.


1 Answers

Copy in the files using Explorer, then in the solution explorer tick the Show All files option in the button bar of the solution explorer (you might need to select a Project first).

Show All Files

You can now right-click any files not part of the projects and choose Include in Project.

Include in Project

Or use the Add Existing File option.

The reason files are not added automatically to your solution when pasted into the folder using Explorer is because you might not want to have them added.

A neat little trick is to use the "Open In explorer" option:

Open in Explorer

(though it might be added by the Productivity Power Tools).

Plus, you can Drag&Drop files directly from explorer to the Visual Studio (when they're both running in the same elevation level if you have User Account Control enabled). To fix the UAC issues, you can either run Explorer as administrator too or install the VSCommands extension.

And you can Copy&Paste a file or set of files into the solution explorer by right-clicking a project or project folder and picking Paste on the context menu.

like image 144
jessehouwing Avatar answered Oct 28 '22 01:10

jessehouwing