Folders or Projects in a Visual Studio Solution? [

2020-05-14 18:56发布

When spliting a solution in to logical layers, when is it best to use a separate project over just grouping by a folder?

7条回答
Root(大扎)
2楼-- · 2020-05-14 19:11

denny wrote:

I personally feel that if reusable code is split into projects it is simpler to use other places than if it is just in folders.

I really agree with this - if you can reuse it, it should be in a separate project. With that said, it's also very difficult to reuse effectively :)

Here at SO, we've tried to be very simple with three projects:

  • MVC Web project (which does a nice job of separating your layers into folders by default)
  • Database project for source control of our DB
  • Unit tests against MVC models/controllers

I can't speak for everyone, but I'm happy with how simple we've kept it - really speeds the builds along!

查看更多
时光不老,我们不散
3楼-- · 2020-05-14 19:15

I really think it is better to split the project as well, but it all depends on the size of the project and the number of people working on it.

For larger projects, I have a projects for

  • data access (models)
  • services
  • front end
  • tests

I got the model from Rob Connery and his storefront application... seems to work really well.

mvc-storefront

查看更多
乱世女痞
4楼-- · 2020-05-14 19:16

I usually do a project for the GUI a project for the business logic a project for data access and a project for unit tests.

But sometimes it is prudent to have separation based upon services (if you are using a service oriented architecture) Such as Authentication, Sales, etc.

I guess the rule of thumb that I work off of is that if you can see it as a component that has a clear separation of concerns then a different project could be prudent. But I would think that folders versus projects could just be a preference or philosophy.

I personally feel that if reusable code is split into projects it is simpler to use other places than if it is just in folders.

查看更多
该账号已被封号
5楼-- · 2020-05-14 19:23

Separating your source code into multiple projects makes only sense if you... ... More developers involved and you want to treat their work as consumable black box. (not very recommended) ...

Why isn't this recommended? I've found it a very useful way to manage an application with several devs working on different portions. Makes checkins much easier, mainly by virtually eliminating merges. Very rarely will two devs have to work on the same project at the same time.

查看更多
forever°为你锁心
6楼-- · 2020-05-14 19:28

By default, always just create new folder within the same project

  • You will get single assembly (without additional ILMerge gymnastic)
  • Easier to obfuscate (because you will have less public types and methods, ideally none at all)

Separating your source code into multiple projects makes only sense if you...

  • Have some portions of the source code that are part of the project but not deployable by default or at all (unit tests, extra plugins etc.)
  • More developers involved and you want to treat their work as consumable black box. (not very recommended)
  • If you can clearly separate your project into isolated layers/modules and you want to make sure that they can't cross-consume internal members. (also not recommended because you will need to decide which aspect is the most important)

If you think that some portions of your source code could be reusable, still don't create it as a new project. Just wait until you will really want to reuse it in another solution and isolate it out of original project as needed. Programming is not a lego, reusing is usually very difficult and often won't happen as planned.

查看更多
7楼-- · 2020-05-14 19:32

If you do go for creating several projects, make sure everyone who adds code to the solution is fully aware of the intention of them and do everything you can to get them to understand the dependencies between the projects. If you have ever tried to sort out the mess when someone has gone and added references that shouldn't have been there and got away with it for weeks you will understand this point

查看更多
登录 后发表回答