Is there a way to drag & drop to copy files between two visual studio instances? - visual-studio

Is there a way to copy files between two Visual Studio 2008 instances ? A plugin, setting, or something else ? Currently, dragging a file from one instances to another does nothing (mouse shows that it's invalid operation).
Right-clicking a file and selecting "Copy" from instance 1, and pasting in instance 2 results in the following error:
The source files for this operation cannot be found in this solution.
Any ideas or solutions ?

About the only way you can do that, is to right-click, Add Existing Item and browse for the file. Ridiculous, I know, but thats the way it is ;)

Got me the Visual Studio extension Open In Explorer that provides a context menu option "copy files". This way you don't have to go over a windows explorer window.

Very frustrating, I know.
The thing is that if you copy it directly to the file system, it may not be included in the TSF.
My advice is:
Copy, or drag the files from the file system (i.e. Windows Explorer)
Paste, or drop them in the Visual Studio Solution Explorer
Worked for me :-)

The simplest built-in way I have found (for VS2019) is:
Right click on the source file
Select Copy Full Path
Switch to the destination solution/project
Right click on the destination folder
Select Add -> Existing item
Paste
Click OK
This will copy the file from source to destination. (Leaving the original alone).
I prefer this as it avoids any tedious browsing through folders.

There's no direct way. One way would be to right click on the folder in the solution explorer, open the folder in explorer, then drag from there into the other instance of Visual Studio.

Just add your source project to your target solution. That will allow you to copy/paste between the two instances of Visual Studio. This works because Visual Studio's clipboard data for copied files must have a representation that's relative to the project identifier.
Futhermore, once you've added the source project to the target solution, you don't even need to copy between instances, because your source project is in the same solution you're copying to. You can probably even CTRL+drag files to copy them so you don't lose text in your clipboard. When you're done, you can remove the project. This is far simpler than opening multiple explorer windows, copying file, clicking 'show all files' in solution explorer, and manually adding the new files.
When your source project is not in your target solution and you try to copy files between instances, you'll get an error like this.
This does not occur when your source project (in one instance) is also in your target solution (in another instance) of Visual Studio. Once you understand what's happening, you'll do a face palm, because the error is literally telling you what the problem is.

Go to file explorer then which files do you want to put in your project, just select them. Now copy those files and paste them on to project. You can also past folders with sub folders and files into project.

Related

How to duplicate a source file in visual studio

in visual studio 2019 on windows, if you right click on a .cs source file in the solution explorer, you have the option to copy. There is no duplicate option. If you copy, there is no paste option. There is no duplicate or paste in the file or edit menu either. There is no ctrl-v option either.
Any ideas?
I cant find any way to add a source file either. If I right click on the directory such as "blocks" where my current source files in my project are, then click "add", the menu which pops up "controller" is greyed out, as is "class".
There are no permissions issues - this is just a project I have been working on but is now "broken". If I go to the root of the project in solution explorer, it has the option to create controllers for example, but bazarely not folders or classes.
If I create a new .cs file in one of the source folders using windows file explorer, there seems to be no option to get this new file picked up by visual studio. The refresh icon at the top of the solution explorer is greyed out, and F5 does nothing.
Well, took me a while to figure this one out. Unlike every other IDE I have used for the last 20 years (eclipse, intellij etc), VS is for some reason making the entire project read only when its running locally. I have to stop it running to be able to add files etc.

Doubling file names in Visual Studio 2012

In Visual Studio 2012 in Solution Explorer window have doubled file names (sorry for no screenshots - here is the link http://floomby.ru/s1/uaxC8K).
In the same time it's all right in File Explorer and in project file (http://floomby.ru/s1/WaxCv8).
It's really annoying thing and cant find the reason why is this happening. What can be done to prevent such behavior?
Still can't describe how to prevent, except it's just use the Visual Studio 2012 merge tool more accuratly. But here is the solution to get rid of duplicate entries in Solution window.
First remember somehow all name of duplicated files (PrtScr or smth else)
Unload the project (call context menu on project name, item "Unload Project")
Edit "ProjectName.xxproj" (call context menu on project name, item "Edit Project.xxproj")
Ctrl+F, paste the name of duplicated file, choose Find All. Look in Find Results window for absolutely identical entries of project files and remove one of them (https://docs.google.com/file/d/0B0NKNNSBiGejeV8wZ3g0WEYzcTA/edit?usp=sharing).
Save changes and Reload Project
Another way is that
Exclude duplicate files from project
Click on "Show all files" button on top of solution explorer
Click again on "Show all files" button on top of solution explorer (this time you should see only one excluded file)
Include file again
You can do this on folders too

MS Visual Studio.net - saved source files missing after reboot

The other day I created a MS visual studio 2010 C# project and started coding. I saved the source frequently, but I did not select a destination to save to (just pressed ctrl+s and assumed the source was being saved). However I had to run and threw my laptop in my backpack on sleep. Unfortunately this laptop (acer aspire 5252 fyi) battery drains extremely quickly when on sleep, and eventually my computer shut off. Now I can't find my source files anywhere and I'm going crazy because I know I saved it and it's several days worth of work.
I tried doing a windows search but couldn't find the project files. I also did a little experiment - I created a new project and without saving the entire solution, I pressed ctrl+s on the source files. Save was successful, but I cannot even find the file that's open in the IDE. Even the "open containing folder option" is grayed out (see screen shot).
I really need these source files back. Obviously it's because I didn't save the solution that the source got wiped out, but where do the source files get saved temporarily before the solution is saved?
Thanks.
You are using Visual Studio's support for temporary projects. Nice feature for quicky test projects (and SO answers) but not a great way to ensure that your projects are still there after VS quits. Programming without source control is similarly inadvisable.
Tools + Options, Projects and Solutions, General. Ensure that the "Save new projects when created" option is ticked to minimize the odds that you'll forget to pick a solution folder. Triple-check that creating a new project now gives you a "Location" property in the dialog.
There is a default location for projects to be saved. That is probably where your files went.
In Visual Studio, on the menu, click Tools > Options > Projects and Solutions > General. There is a "Visual Studio projects location".
On my Windows 7 machine, the folder for Visual Studio 2010 is
C:\Users\<username>\Documents\Visual Studio 2010\Projects
Your unnamed project is probably saved with a default name like WebSite1.
If you would like to change that default location, here is some information on how to do that.
Visual Studio temporary projects are normally found in *C:\Users\"User Name"\AppData\Local\Temporary Projects* . It is a temporary folder that is deleted as soon as Visual Studio starts up.
How to save a Temporay Project from above link:
To save a temporary project
In Solution Explorer, choose the solution or project that you want to save.
On the menu bar, choose File, Save or Save As.
The Save Project dialog box opens.
In the , Name box, specify a name for the project.
In the Location box, specify where you want to save the project.
Select the Create directory for Solution check box.
Note: This check box is not available for Visual Basic web projects, Visual C# web projects, or other directory-based projects.
In the New Solution Name box, specify a name that differs from the project name.
Select the Add to Source Control check box if you want to add the solution to a version-control database or repository.
Choose the OK button.

VS2010 "Add Item" directory change

Is there any way to change the default directory Visual Studio 2010 uses when you add a source file through Add -> New Item?
Add New Item simply adds the item based on which project directory you're currently in or have selected in your Solution Explorer. If you want to change where it gets added then select the target location in the Solution Explorer first.
This behavior is obvious when right-clicking in the Solution Explorer, but it's also the same when using Project -> Add New Item....
Since my comment seems to be the actual answer, I repost:
In the toolbar of Solution Explorer, there's a button "Show all files" (or similar, I'm using the German version). This switches the view to directories, rather than filters. In this view, you can right-click on the desired target folder to add items.
This does not actually change the default directory, but since you have to click somewhere anyway to add an item, this is the easiest approach.
Note that even when only using Visual C++, I'd recommend the Productivity Power Tools extension, which comes with Solution Navigator. In C++, this is not as powerful as with .NET, but it still has several features that are useful in C++ and can fully replace Solution Explorer.
Try going to tools -> options -> Project and Solutions.
I know this post is old... but maybe someone will stumble upon it... like I did today...
I had the same "problem":
I have a dedicated directory for icons.
When I need to add an icon to the resource file, Visual studio takes me to "C:\Program Files (x86)\Microsoft Visual Studio 10.0\Common7\IDE"
To fix the problem, after I "browsed" to the desired folder, I right-clicked the favorites of the "open file" dialog and selected "add current location to Favorites".
Next time you will get this dialog, you simply have to look for the folder in the favorites, and click it.

How do I "Add Existing Item" an entire directory structure in Visual Studio?

I have a free standing set of files not affiliated with any C# project at all that reside in a complicated nested directory structure.
I want to add them in that format to a different directory in an ASP.NET web application I am working on; while retaining the same structure. So, I copied the folder into the target location of my project and I tried to “add existing item” only to lose the previous folder hierarchy.
Usually I have re-created the directories by hand, copied across on a one-to-one basis, and then added existing items. There are simply too many directories/items in this case.
So how do you add existing directories and files in Visual Studio 2008?
Drag the files / folders from Windows Explorer into the Solution Explorer. It will add them all. Note this doesn't work if Visual Studio is in Administrator Mode, because Windows Explorer is a User Mode process.
Enable "Show All Files" for the specific project (you might need to hit "Refresh" to see them)**.
The folders/files that are not part of your project appear slightly "lighter" in the project tree.
Right click the folders/files you want to add and click "Include In Project". It will recursively add folders/files to the project.
** These buttons are located on the mini Solution Explorer toolbar.
** Make sure you are NOT in debug mode.
In Solution Explorer:
Click Show All Files (second icon from the left at the top of Solution Explorer).
Locate the folder you want to add.
Right-click and select "Include in Project"
I use this to install add-ons like HTML editors and third-party file browsers.
I just want to point out that two of the solutions offered previously,
Drag and drop from Windows Explorer
Show All Files and then include in project.
do not do what the question asked for:
Include in project while preserving the directory structure.
At least not in my case (C++/CLI project Visual Studio 2013 on Windows 7).
In Visual Studio, once you are back in the normal view (not Show All Files), the files you added are all listed at the top level of the project.
Yes, on disk they still reside where they were, but in Solution Explorer they are loose.
I did not find a way around it except recreating the directory structure in Solution Explorer and then doing Add Existing Items at the right location.
I didn't immediately understand this based upon these descriptions but here is what I finally stumbled on:
Turn on "Show All Files" - there is an icon on the Solution Explorer toolbar
Using Windows Explorer (not solution explorer), move your files into the directory structure where you want them to reside
Click "Refresh" also on the Solution Explorer toolbar
The files that you've moved should be visible "ghosted" in the Solution Explorer tree structure where you've placed them
Right click on your ghosted files or folders and click "Include in Project". All the contents of a folder will be included
Below is the icon for the 'Show All Files', just for easy reference.
Click above in the red circle. Your folder will appear in Solution Explorer.
Right click on your folder -> Include in project.
You can change your project XML to add existing subfolders and structures automatically into your project like "node_modules" from NPM:
This is for older MSBuild / Visual Studio versions
<ItemGroup>
<Item Include="$([System.IO.Directory]::GetFiles("$(MSBuildProjectDirectory)\node_modules","*",SearchOption.AllDirectories))"></Item>
</ItemGroup>
For the current MSBuild / Visual Studio versions:
Just put it in the nodes of the xml:
<Project>
</Project>
In this case just change $(MSBuildProjectDirectory)\node_modules to your folder name.
You need to put your directory structure in your project directory. And then click "Show All Files" icon in the top of Solution Explorer toolbox. After that, the added directory will be shown up. You will then need to select this directory, right click, and choose "Include in Project."
This is what I do:
Right click on solution -> Add -> Existing Website...
Choose the folder where your website is. Just the root folder of the site.
Then everything will be added on your solution from folders to files, and files inside those folders.
At last, Visual Studio 2017 allows the user to import an entire directory with a single click. Visual Studio 2017 has a new functionality "Open Folder" that allows opening the entire folder, even without the need to save it as solution. The source code can be imported using the following methods.
Menu File → Open → *Folder (Ctrl + Shift + O)
devenv.exe <source folder>
It even supports building and debugging CMake projects.
Bring your C++ codebase to Visual Studio with “Open Folder”
There is now an open-source extension in the Marketplace that seems to do what the OP was asking for:
Folder To Solution Folder
If it doesn't do exactly what you want, the code is available, so you can modify it to suit your scenario.
HTH
A neat trick I discovered is that if you go to "Add existing...", you can drag the folder from the open dialog to your solution.
I have my Visual Studio to open in Admin Mode automatically, so this was a good workaround for me as I didn't want to have to undo that just to get this to work.
What worked for me was to drag the folder into Visual Studio, then right click the folder and select "Open Folder in File Explorer". Then select all and drag them into the folder in Visual Studio.
In Windows 7 you could do the following:
Right click on your project and select "Add->Existing Item". In the dialog which appears, browse to the root of the directory you want to add. In the upper right corner you have a search box. Type *.cs or *.cpp, whatever the type of files you want to add. After the search finishes, select all files, click Add and wait for a while...
The cleanest way that I've found to do this is to create a new Class Library project in the target folder, and redirect all of its build output elsewhere. It still leaves a .csproj file sitting in that folder, but it does let you see it in Visual Studio and pick which files to include in your project.
It has been a while since this was originally posted, but here is an alternative answer.
If you only care to be able to look at the physical files from inside visual studio and do not necessarily require to see them in the solution explorer default view, then click on the switch view button and choose the folder view and any physical directory/directories that are under your solution root folder will appear here even if they do not appear in the solution explorer default view.
If however, you want to add a folder tree that isn't too large as a virtual solution directory/directories to match your existing tree structure, do that and and then "add the existing" physical files to the virtual directory/directories. If the physical directory exists in your solution directory it will not copy the files - it will link directly to the physical files but they will appear as part of the solution virtual directories.
It's annoying that Visual Studio doesn't support this natively, but CMake could generate the Visual Studio project as a work around.
Other than that, just use Qt Creator. It can then export a Visual Studio project.

Resources