visual-studio Visual Studio 项目/解决方案结构是否有最佳实践?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/284856/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Is there any best practices for Visual Studio Project/Solution Structure?
提问by JamesEggers
I've seen a lot of different takes on this subject so I figured if there's a preferred way on this.
我在这个主题上看到了很多不同的看法,所以我想在这方面是否有首选的方法。
Is there any best practices on how to setup Visual Studio Projects and Solutions in regards to multiple solutions for the same solutions?
对于相同解决方案的多个解决方案,是否有关于如何设置 Visual Studio 项目和解决方案的最佳实践?
For example: Let's say I have a task that calls for a web app, a console application, and a shared business logic library.
例如:假设我有一个任务需要一个 Web 应用程序、一个控制台应用程序和一个共享的业务逻辑库。
I have seen this situation in a 1, 2, and 3 solutions at some time in my career. This is a simple example; however, what if number of projects grows? Is there a line when to keep it in one or break it apart?
在我职业生涯的某个时候,我曾在 1、2 和 3 解决方案中看到过这种情况。这是一个简单的例子;但是,如果项目数量增加怎么办?什么时候把它放在一个里面或把它分开,是否有一条线?
采纳答案by Greg D
Indeed, there are some guidelines for this sort of setup on MSDN. I wrote a short summary in my answer to a similar questionon StackOverflow.
事实上,在MSDN上有一些关于这种设置的指导方针。我在 StackOverflow 上对类似问题的回答中写了一个简短的总结。
回答by Mike Hadlow
I blogged about this back in 2007. The advice still holds:
我早在 2007 年就在博客上写过这个。建议仍然成立:
http://mikehadlow.blogspot.com/2007/07/how-to-structure-visual-studio.html
http://mikehadlow.blogspot.com/2007/07/how-to-structure-visual-studio.html
The bottom line is that I should be able to get your code out of source control, open it in Visual Studio, hit F5 and everything should work.
最重要的是,我应该能够让你的代码脱离源代码管理,在 Visual Studio 中打开它,按 F5,一切都应该正常工作。
回答by Brad Bruce
Solutions are for the developer, in a particular situation. Projects (.CSPROJ for C-Sharp) are where the real compilation takes place.
解决方案适用于特定情况下的开发人员。项目(C-Sharp 的 .CSPROJ)是真正编译发生的地方。
Theoretically if there are 4 different projects, there could be 24 different combinations of those projects a developer may want to combine into solutions.
从理论上讲,如果有 4 个不同的项目,那么开发人员可能希望将这些项目组合成解决方案的 24 种不同组合。
If you keep everything at a project level, you won't need to worry about how a developer has arranged their .SLN files
如果您将所有内容都保留在项目级别,则无需担心开发人员如何安排他们的 .SLN 文件
回答by PJ8
You can have multipe solutions, and each one can reference the projects that it cares about. Extending your example, your shared business logic library may have a corresponding unit test library. These two projects can be contained in one solution. At the same time, you may have another solution that contains the three projects that you mention, but in this case the unit test library isn't included.
您可以有多种解决方案,每个解决方案都可以引用它所关心的项目。扩展您的示例,您的共享业务逻辑库可能具有相应的单元测试库。这两个项目可以包含在一个解决方案中。同时,您可能有另一个包含您提到的三个项目的解决方案,但在这种情况下,单元测试库不包括在内。
回答by Kon
My solutions typically consist of:
我的解决方案通常包括:
- Web Application project
- 'Common' folder for base & common helper classes
- 'Include' folder
- 'Styles' folder
- 'Scripts' folder
- 'Images' folder
- 'UserControls' folder
- Web Services project
- Web Framework project
- Business Tier project
- Business Framework project
- Data Access project
- 网络应用项目
- 基本和通用助手类的“通用”文件夹
- “包含”文件夹
- “样式”文件夹
- “脚本”文件夹
- “图片”文件夹
- “用户控件”文件夹
- 网络服务项目
- 网络框架项目
- 业务层项目
- 业务框架项目
- 数据访问项目
回答by CheGueVerra
I like to include all projects for a certain task, in a solution. So based on the example you mention, I would have a solution containing the three projects that belong to the solution I was asked to do. That keeps all elements to complete a task together, I find this simplifies the inclusion of other elements required to solve the task at hand.
我喜欢在解决方案中包含某个任务的所有项目。因此,根据您提到的示例,我将有一个解决方案,其中包含属于我被要求执行的解决方案的三个项目。这使完成任务的所有元素保持在一起,我发现这简化了解决手头任务所需的其他元素的包含。

