重新组织Visual Studio解决方案的目录结构 [英] Reorganizing directory structure for Visual Studio solution

查看:291
本文介绍了重新组织Visual Studio解决方案的目录结构的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的Visual Studio(VS)项目/解决方案按预期工作,但是VS以某种非逻辑的方式以某种方式组织了我项目的目录结构(源文件).

My Visual Studio (VS) project/solution works as intended, but VS has somehow organized the directory structure (source files) of my project in a non-logical way.

当前目录结构

Solution Folder
    Project 1 folder
        Project 1 source files
    Sub folder
        Project 2 source files
        .sln Solution file
        Project 3 folder
            Project 3 source files

我想在VS中将项目添加到解决方案时,有时会犯错,因为它现在是这样组织的.

I guess I have made a mistake at some point when adding the projects to the solution in VS, since it is organized like this now.

理想情况下,我希望的是这种更干净的结构:

What I would ideally like is this more clean structure:

Solution Folder
    Project 1 folder
        Project 1 source files
    Project 2 folder
        Project 2 source files
    Project 3 folder
        Project 3 sources files
    .sln Solution file

当我尝试执行此操作时-或每当我根据上述内容通过简单地移动它们而在VS之外移动/尝试重新组织VS之外的文件/文件夹,然后尝试在VS中构建解决方案时,都会收到以下错误消息: (几乎)所有项目:

When I tried this - or whenver I move/try to reorganize the files/folders outside of VS according to the above by simply moving them around, and then try to build the solution in VS afterwards, I get the following error for (pretty much) all items:

The item (name) does not exist in the project directory.
It may have been moved, renamed or deleted.

所以我的问题是:

如何在VS之外为解决方案重新组织我的文件夹/文件,而又不破坏解决方案?

推荐答案

对于那些可能遇到类似障碍的人,我从以下主题中找到了答案:

For people who might be having similar obstacle, I found the answer to it from this thread:

Visual Studio将项目移至其他文件夹

如此处所述,您必须从Visual Studio(VS)的解决方案资源管理器中删除要移动的项目.然后,将项目文件夹(VS外部)移动到所需的位置.最后,在VS解决方案资源管理器中,右键单击解决方案->添加->现有项目. 确保不要分开属于同一文件夹或文件(非常小心/意识到这一点).

As described in there, you have to delete the project you wish to move from inside your Solution Explorer in Visual Studio (VS). Afterwards, you move the project folder (outside VS) to where-ever you want it. Finally, in VS Solution Explorer, you right click on your Solution --> Add --> Existing project. Make sure you dont separate any folders or files, that belong together (be very careful/aware of this).

如果您要引用其他项目,例如通过名称空间,您只需简单地右键单击要引用另一个项目的项目(在解决方案资源管理器中)->添加->引用,即可再次添加它.

If you were referencing the different projects e.g. through namespaces, you have to add this again simply by right clicking the project (in Solution Explorer) that you want to reference another project --> Add --> Reference.

由于某种原因,Visual Studio可能会在构建/调试等过程中更改哪个项目正在首先初始化.如果在VS Solution Explorer中查看,则首先初始化的项目为粗体.如果需要更改此设置,请右键单击所需的启动项目->设置为启动项目".

Visual Studio might, for whatever reason, change which project is initializing first when building/debugging etc. If you look in VS Solution Explorer, the project which is initialized first is bold. If you need to change this, right-click on your desired start-up project --> Set as StartUp Project.

以上所有内容适用于 Visual Studio 2017

这篇关于重新组织Visual Studio解决方案的目录结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆