How do I add an existing directory tree to a proje

2019-01-03 07:17发布

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?

10条回答
倾城 Initia
2楼-- · 2019-01-03 08:03

In Visual Studio 2013, I couldn't get "Include in Project" to work when right-clicking on a folder. What did work is expanding the folder, selecting all the files then choosing "Include in Project". It was quite tedious as you have to do each folder one by one (but at least you can do all files in each folder in one go), and it appears to store the file path (you can see this by viewing properties on the file and looking at the "Relative Path" option.)

I am hoping to use this to deploy some data files in a Visual Studio Installer project, and it seems to pick up the included files and preserve their paths.

查看更多
等我变得足够好
3楼-- · 2019-01-03 08:04

You can use a symbolic link. This makes modifying the file in one project modify it in the other (as it's actually the same file).

To do this:

  1. Open cmd prompt as administrator
  2. mklink /d [current project directory name] [directory in other project it should point to]

This has it's drawbacks and pitfalls, but I use it on occasion for duplicate libraries that need different names.

Edit for Anoop: Steps to add to Visual Studio:

  1. Create link in the project folder using the steps above.
  2. In Visual Studio... select project in Solution Explorer.
  3. At the top of Solution Explorer... click the Show All Files button (may need to click it twice if already active).
  4. The link will now show in your project... right-click and choose Include In Project.

These are the steps I follow and works for a couple different projects.

查看更多
We Are One
4楼-- · 2019-01-03 08:05

You can also drag and drop the folder from Windows Explorer onto your Visual Studio solution window.

查看更多
\"骚年 ilove
5楼-- · 2019-01-03 08:13

In Visual Studio 2017, you switch between Solution View and Folder View back and forth. I think this is a better option, because it will keep the solution cleaner. I use this to edit .gitignore, .md files, etc.

Solution View and Folder View

查看更多
登录 后发表回答