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

前端 未结 18 1270
眼角桃花
眼角桃花 2020-11-28 00:18

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 for

相关标签:
18条回答
  • 2020-11-28 00:44

    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.

    0 讨论(0)
  • 2020-11-28 00:47

    Click above in the red circle. Your folder will appear in Solution Explorer.

    Right click on your folder -> Include in project.

    0 讨论(0)
  • 2020-11-28 00:48

    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(&quot;$(MSBuildProjectDirectory)\node_modules&quot;,&quot;*&quot;,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.

    0 讨论(0)
  • 2020-11-28 00:49

    I didn't immediately understand this based upon these descriptions but here is what I finally stumbled on:

    1. Turn on "Show All Files" - there is an icon on the Solution Explorer toolbar
    2. Using Windows Explorer (not solution explorer), move your files into the directory structure where you want them to reside
    3. Click "Refresh" also on the Solution Explorer toolbar
    4. The files that you've moved should be visible "ghosted" in the Solution Explorer tree structure where you've placed them
    5. Right click on your ghosted files or folders and click "Include in Project". All the contents of a folder will be included
    0 讨论(0)
  • 2020-11-28 00:50

    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.

    0 讨论(0)
  • 2020-11-28 00:51

    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.

    0 讨论(0)
提交回复
热议问题