Visual Studio, Copy files to project directory problem - visual-studio

I have Visual Studio community 2017. coming from eclipse it was just enough to copy file to project directory and hit refresh then files were appearing in project explorer.
In VS, however when I copy some i.e. *.cpp or *.h in windows explorer to project directory, in VS solution explorer I can not see them. switching to folder view I see but can not include them into project.
via drag&drop to solution explorer (project view) I see them but are not part of project and in folder view and actual directory there is nothing.
what is going on with VS? How can I manually copy paste some files into project while they become part of project?

I will note that there's nothing "going on" with Visual Studio in the sense that something is actually wrong with it, it's just that adding files to your project just requires you to actually add them to your solution. Essentially, it allows you to add miscellaneous files to your folders without automatically including them in your build project (for example, if you're working with some test images/files).
To add files/folders to your project you simply right click on your project in the Solution Explorer and then go to Add > Existing Item.... Then, it's just a matter of selecting one (or Ctrl + A/Shift Clicking to select all/multiple files) and then it will add them to your solution.

In the solution explorer pane, click on the show all files button,
it will reveal all files including your pasted file,
Right click on your file and select "include in project".

Related

How to add folders structure in VS2015?

In older versions of VS when you dragged a folder from windows file explorer into your VS solution, it would make a reference to that folder including all the sub folders' structure and files.
In VS2015 when I drag a folder into the solution it simpley makes a reference to all the files in that folder and sub folder but ignore the folder structure.
So it dumps all the files reference under one filter.
Is there a way to get the former behavior in VS2015?
The way that I do this is to add the folders to the project structure (i.e. underneath the .sln file) and then enable "Show All Files" (you may need a "Refresh").
Right click the folders you want to add and click "Include In Project".
(I didn't know about the drag and drop!)
The answer is as follows:
the reason you don't see the "include in project" is : either you created the solution externally to visual studio community or the solution got corrupt
to resolve this:
make a backup the solution (just in case)
in solution explorer - right click the project name , and choose "Rebuil solution"
Press the "show all files" (if not pressed already)
go to the folder you want to include, and now you should see the "include in project" option. Choose it
press again the "show all files" button (on top of the "solution explorer") to once again hide irrelevant files/folders from your solution explorer
Working with VS2015 and SSIS Solution:
Miscellaneous Folder - When I created a Sub-Folder in VS2015 and then Added the files contained therein it added them but not with the Name I Had but the name "Miscellaneous". Not how it worked in previous versions!
I was able to Add a Custom-Named Folder to the Solution but not the Project. When adding existing files to the Project it put them under the aforementioned Miscellaneous Folder.

Creating an installer for Visual Studio 2010 solutions (one or more projects)

I ran into some troubles when creating an installer for my Visual Studio 2010 solution (which has multiple projects) so I thought I'd make a quick guide to how I got it working...
Here is how I did it:
Create a new Visual Studio Installer project which is located under
Installed Templates/Other Project Types/Setup and Deployment/Visual Studio Installer.
Make sure you add it to you current solution, you can do this by right clicking on the solution name in the solution explorer and clicking Add>New Project
From there select Setup Wizard, give it a name and click OK
A wizard will open, click Next
then select Create a setup for a Windows application
then click Next again. Select all of the groups you want to include, namely: Content Files, Source Files, Primary Output
Then click Finish
In the solution explorer you will see a bunch of buttons find the one that's tool tip says File System Editor and click it. You will see three folders in the file system editor, the only one we really care about is the Application Folder. That folder is where your projects build output should be.
To add files to it if they are not already there right click > Add > File...
Note: You cannot add entire folders (which sucks) and the folder structure in the Application Folder should be identical to that in your projects build.
You should create each folder and then add the files to it.
If you have multiple projects you should set the build directory to the same folder under the release build settings. To do this, open your solution, and for each project, right click/Properties go to the Compile tab, set it's configuration to Releaseand its Build output path to some folder (same for each project) (If you have an XNA project make sure its Content Build/Configuration is also set to Release).
Now select Release from the drop down menu on the tool bar (it most likely says Debug now)
Right click on your solution on the solution explorer and click Build Solution
Now all of your solutions built files will appear in the folder you chose in the compile tab. All of these files are what needs to be added to the Setup Projects Application Folder (in the same structure)
Customise the installer: click on the project name in the solution explorer and look through it's properties, change what you want (i.e Author, Manufacturer, Title - these make a difference to the installers output directory and text)
Build the installer project (same way as mentioned above) and you are done.
Feel free to comment with questions

How To ReInclude Excluded Folder

So I just performed the coup de gras on my project by accidentally clicking on Exclude From Project instead of Add on my controllers folder.
When trying to add a folder named Controllers I get the error "this folder exists". However, If I try to click on the project -> Add Existing... I cannot select a folder, but only the controllers.
Kind of at a loss here, has anyone had experience with this, or does anyone know how to get the folders back into the solution?
Click on the Show All Files icon in the solution explorer and then simply include the folder:
Visual Studio Express 2012
Select Your Project Folder Click On "Show All Files" icon to show all Excluded Folders And Files
Then Right Click on Excluded Folder or File and Click on "Include In Project"
In my ASP.Net Webforms project after excluding the file I could't find it even under 'Show all files', but they were at project folder so I had to right click on project in Visula Studio then add existing item.
For anyone wanting a different solution, you can also browse to your project in a File Explorer and delete the offending folder (Be sure to copy it somewhere safe first!). Restart Visual Studio and proceed to add the folder as you regularly would.

adding multiple existing folders and multiple existing files to Visual Studio project in single step

Does anyone have a way to add multiple folders and (existing) files within those folders to a Visual Studio project in a single step (or via macro)? Let's assume all of the folders and files were copied/pasted into the project folder where they need to reside relative to the project folder, but are not actually stored in the .csproj or .vbproj file, which I believe is a requirement to compile those files into the solution/project.
This works great if you have a web application project in your solution, but not so well if you have a .csproj or .vbproj. In that case, you must manually add folders (and nested folders), and add existing files and browse to each one individually, which can take a long time.
In the solution explorer, select the project, click the "Show All Files" button - .
This will show all the files, even those not part of the project. You can now select all of these in the solution explorer (using Ctrl + Click) then right click and go to "Include In Project".
In Visual Studio 2013 (and possibly earlier) you drag the folder from windows explorer and drop it on the project in the solution explorer.
Other answer given in this thread wouldn't work for me as the files I want to add (DTSX files) are in a different folder, and copying/moving them causes other problems. Here is what worked for me:
Using Visual Studio 2015, use Windows Explorer to locate the files you want to add to your project. Copy those files to the clipboard. If DTSX files are what you are dealing with, in the Solution Explorer right-click on SSIS Packages, and then click on Paste.

Visual Studio move project to a different folder

How do I move a project to a different folder in Visual Studio? I am used to this structure in my projects.
-- app
---- Project.Something
---- Project.SomethingElse
I want to rename the whole namespace SomethingElse to SomethingNew, what's the best way to do that (without manually going into .sln file)?
Remove the project from your solution by right-clicking it in the Solution Explorer window and choosing Remove. Move the entire project folder, including subdirectories wherever you want it to go. Add the project back to your solution.
Namespace names is something completely different, just edit the source code.
I tried the suggestion to remove and re-add the project, but then fixing up dependencies can be a pain.
I use this approach:
Move the project folder.
If the project is in source control, do the move using source control commands.
Edit the solution file in a text editor. There should be only one path that you need to change.
Close your solution in VS2012
Move your project to the new location
Open your solution
Select the project that failed to load
In the Properties tool window, there an editable “File path” entry that allows you to select the new project location
Set the new path
Right click on the project and click reload
Summary: rename-and-move in VS2019 with git, retaining git history, leveraging R# a bit, automatic dependent project reference updating (important for sln's with many projects, we have >200)
I have been using the following steps to rename-and-move C# projects in Visual Studio 2019. This process uses R# to adjust namespaces. The git history is retained by doing a "git mv" (avoiding add/delete history drop).
Two phases: 1) rename the project in place and 2) move the project.
(Uses tip from base2 re unloading projects.)
Rename
VS | Solution Explorer | right-click project | Rename (e.g., Utils.Foo to Foo).
VS | Solution Explorer | right-click project | Properties | change assembly name, default namespace and Assembly Information fields
Do 1 and 2 for corresponding test project (e.g., Utils.Foo.Tests)
VS | Solution Explorer | right-click projects (production and test) | Refactor | Adjust Namespaces
XAML files that use the project may need to be updated (manually or with an appropriate global search and replace)
Rebuild All
Commit!! (to commit changes before moves)
Note: The folder in Windows Explorer remains the old name to this point (e.g., Utils.Foo). This is fixed in the move steps.
Move
This method: 1) retains git history, 2) leverages R# to adjust namespaces atomically and 3) updates dependent projects en masse (avoids tedious manual editing of dependent sln and csproj files).
unload all the projects in the solution (so that removal of the target project does not trigger changes in dependent projects)
VS | select all solution folders under the Solution | right-click Unload Projects
move folders using git (so history is maintained)
a) open Developer Command Prompt for 2019
b) git status (to illustrate “nothing to commit, working tree clean”)
c) git mv the project
e.g., git mv "C:\Code\foo\foo\Utils.Foo" "C:\Code\Foo"
d) git status to view/verify change
remove the project
VS | Solution Explorer | select project | right-click | Remove
(since all projects are unloaded, this will correctly NOT remove the references to it in dependent projects)
re-add the project (to the new location in the tree in Solution Explorer)
a) VS | Solution Explorer | select target parent folder | right-click | Add | Existing Project
reload all projects
IMPORTANT: Confirm that *.csproj files for dependent projects have been updated.
(VS | Team Explorer | Changes | double-click any dependent csproj listed | inspect-verify ProjectReference path change)
Manually fix paths in the single moved *.csproj file
Use Notepad++ (or other text editor) to fix the paths. Often this can be done with a simple search-and-replace (e.g., ../../../../ to ../../).
This will update...
a) GlobalAssmeblyInfo.cs references
b) paths to packages
c) paths to Dependency Validation diagram files
d) paths to ruleset paths (e.g., <CodeAnalysisRuleSet>..\..\..\..\SolutionDependencyValidation\IgnoreWarnings.ruleset</CodeAnalysisRuleSet>)
Close and re-Open the solution (to get the project references into good shape)
Save All, Close Solution, I prefer to delete bin and obj folders to be clean of history, Re-open Solution
Validate
a) VS | Team Explorer | Changes
i) should see Staged Changes that reveal the files that moved
ii) should see dependent projects (*.csproj) that were nicely updated
review the csproj diffs and notice that the paths have been beautifully updated!! (this is the magic that avoids laboriously manually updating the csproj files using a text editor)
b) in Windows Explorer, verify old location is empty
c) Clean Solution, Rebuild Solution, Run unit tests, Launch apps in sln.
Commit!!
What worked for me was to:
Remove the project from the solution.
Edit the project file with a text editor.
Update all relative paths to the "packages". In my case I had to change ..\packages to ..\..\..\packages since I moved the project to a deeper folder.
Load the project back into the solution.
I had the same problem. I solved with move the references and in less than 15 minutes, without change the references.
For me the solution was simple:
Move your files where you need.
Delete the folder with name .vs. Must be as not visible folder.
Open the solution file (.sln) using a simple editor like note or
notepad++.
Change the reference where your file is, using the following
structure: if you put your project in the same folder remove the
previous folder or the reference "..\"; if you put in a above folder
add the reference "..\" or the name of the folder.
Save the file with the changes.
Open the project file (.csproj) and do the same, remove or add the
reference.
Save the changes.
Open the solution file.
Examples:
In solution file (.sln)
Original:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.UI",
"ScannerPDF\PATH1.UI\PATH1.UI.csproj",
"{A26438AD-E428-4AE4-8AB8-A5D6933E2D7B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") =
"PATH1.DataService",
"ScannerPDF\PATH1.DataService\PATH1.DataService.csproj",
"{ED5A561B-3674-4613-ADE5-B13661146E2E}"
New:
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PATH1.MX.UI", "PATH1.MX.UI\PATH1.UI.csproj",
"{A26438AD-E428-4AE4-8AB8-A5D6933E2D7B}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") =
"PATH1.DataService",
"PATH1.DataService\PATH1.DataService.csproj",
"{ED5A561B-3674-4613-ADE5-B13661146E2E}"
In project file:
Original:
New:
Original reference:
....\lib\RCWF\2018.1.220.40\TelerikCommon.dll
New reference:
..\lib\RCWF\2018.1.220.40\TelerikCommon.dll
Most easy way, which I found for myself
I tried multiple times till I found a working way.. For example you want to move your project from sln folder to mySource folder.
Remove your Project: In the SolutionExplorer of Visual Studio select your Project you want to change the directory, Press Delete -> Project gets removed. It still remains in your sln folder.
Copy it to your Path: In the windows explorer copy your whole project to your mySource folder. -> Now you are ready to include it.
Include back your Project: In the SolutionExplorer of Visual Studio add Existing Project and select your project from mySource folder. -> Project is now back in your Solution.
Adjust your Project References: Check every Reference in your Project. On your Project -> Dependencies -> Project -> you see your project references. If there is a yellow Warning sign on a project reference than is it wrong. Delete your project reference and add it new.
Rebuild your Project: and let it Run. Afterwards you can delete your project in the sln folder, which is not anymore in use.
That works. Have fun :)
in visual studio comunity 2019, i did what Victor David Francisco Enrique says, but needed only to delete the .vs invisbile folder
It's easy in VS2012; just use the change mapping feature:
Create the folder where you want the solution to be moved to.
Check-in all your project files (if you want to keep you changes), or rollback any checked out files.
Close the solution.
Open the Source Control Explorer.
Right-click the solution, and select "Advanced -> Remove Mapping..."
Change the "Local Folder" value to the one you created in step #1.
Select "Change".
Open the solution by double-clicking it in the source control explorer.
In VS 2015
Unload your project in the solution explorer
Create a new solution
Copy the projects to the new solution's folder
Right click the solution, add existing project.
If you use some framework such as MVC, you may need to add the reference in the reference manager.
I figured out this try this it worked for me.
In visual studio 2017 community edition it creates a project at this path
"C:\Users\mark\source\repos\mipmaps\mipmaps"
This will create a access to file is denied issue
Now, you can fix that this way.
close your visual studio process.
Then, find your project and copy the project folder
But, first make a Sub-folder Named Projects inside of your visual studio 2017 folder in documents.
Next, paste the project folder inside of your visual studio 2017 Project folder not the main visual studio 2017 folder it should go into the Sub-folder called Projects.
Next, restart Visual studio 2017
Then, choose Open project Solution
Then, find your project you pasted in your visual studio 2017 Projects folder
Then clean the Project and rebuild it , It, should build and compile just fine.
Hope, this Helped out anybody else.
Not to sure why Microsoft thought building your projects in a path where it needs write permissions is beyond me.
I wanted the changes in Git to be shown as moves/renames instead of delete & adds.
So I did a combo of the above and this post.
mkdir subdirectory
git mv -k ./* ./subdirectory
# check to make sure everything moved (see below)
git commit
And adjust the paths of the projects and of the assemblies from the nuget Pkg's in the sln file via a text editor.
Copy the project folder to new destination
Remove your project from solution (Right-click the project in "Solution Explorer" and choose "Remove")
Then add existing project to solution (Right-click the project in "Solution Explorer" and choose "Add" then "Existing project")
Change path to "packages" folder in "YourProjectName.csproj" file (Open in notepad and change paths for linked packages)
This worked for me vb2019. I copied my source project folder. I then pasted the project, and renamed the the folder to whatever. In order to break the ties back to the source project folder, I temporarily renamed the source folder. I opened my destination project. The paths to the forms and modules were re-discovered in the local folder. I went through all my forms and modules to make sure they were working. I ran the project. I closed the project. I renamed the source project folder back to is't original name. I can open both projects at the same time without errors.
Close the solution and move your project to new folder/location
Re-open your solution
Project should be loaded with '+' sigh referring as non checked in part. All the files
of the project will be shown as Renamed.
If not working after reopening right click on the project and click unload and then
reload.
It worked in VS2019
Group related projects together using solution folders
See http://msdn.microsoft.com/en-us/library/vstudio/c6c756s6(v=vs.100).aspx
No sure why all answers have overlooked at the most simple solution. Just run the "Command Prompt app" (in the windows bar search for CMD and it will appear automatically)
then just type the following command (change the path where relevant for your own case:)
robocopy /E C:\Users\Peter\source\repos D:\Peter\repos
What robocopy does is to "copies file data from one location to another." and the "secret source" is the / E that means "Copies subdirectories. This option automatically includes empty directories."
Enjoy!!! :-)

Resources