The issue is simple really. Instead of creating folders in Visual Studio, I create a directory structure for my project on the file system. How do I include all the folders and files in a project, keeping the structure?
If I "Add Existing File" on a folder named Services and navigate to a file in the directory structure .. Services > AccountManagement > CreateAccount.cs, it appears in Visual Studio like so: Services > CreateAccount.cs. I do not want this.
I have an entire directory structure worked out already, as I am mimicking our client developers using the same structure for organization. How do I add all the folders and files to the project in Visual Studio? Or do I have to do what most Microsoft users do and "put up with it" and recreate each and every folder through Visual Studio?
Copy & Paste.
To Add a folder, all the sub-directories, and files we can also Copy and Paste. For example we can:
Right click in Windows explorer on the folder, and Copy on the folder with many files and folders.
Then in Visual Studio Solution explorer, right click on the destination folder and click paste.
Optional add to TFS; Then in the top folder right click and check in to TFS to check in all sub-folders and files.
I think I found a way to do this with the Compile Include=".\Code***.cs" What I wanted is to include code recursively under my Code folder.
Here is the project file sample.
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."
As far as I can tell, the only way to do this in VS2010 is akin to the drag and drop method. Right click the solution to which you want to add a project. The application menu will have an add ... item. Opening that, you find that one of the options is to add an existing project to the solution.
In the dialog box that opens, navigate to the folder containing the project file for the solution and select it. VS will, as part of importing that project file, also import the entire directory and, I assume any subordinate directories which are part of that project.
As this does require an existing project file, it won't be impossible to import a directory tree until that tree has been converted to a project.
In Visual Studio 2015, this is how you do it.
If you wanted to automatically include all descendant files below a specific folder:
This can be restricted to include only files within the path specified:
Or even only files with a specified extension:
Reference: http://jamesrpatterson.com/blog/automatic-include-in-project-for-visual-studio
To expand on Yuchen's answer, you can include files and paths as a link. This is not the same thing as adding the existing items because it doesn't make an extra copy in your project's folder structure. It is useful if you want one canonical folder / file etc to be used in a lot of different places but you only want to maintain one version/copy of it.
Here is an example of what you can add to a
*.csproj
file to create the link$(Codez)
is a Windows Environment variable I defined, you can use the built-in Environment variables in the same manner.The last example group is a bunch of content files I need in the final output. See https://stackoverflow.com/a/11808911/492 and other answers & links there for more on that.
More MSBuild info at https://msdn.microsoft.com/en-us/library/bb629388.aspx