在多个项目之间共享代码的最可维护的方法

发布于 2024-09-16 05:44:34 字数 577 浏览 4 评论 0原文

考虑到多个网站都运行相同的源代码,在 Visual Studio 中将这些网站组织到项目中的最佳/最可维护的方法是什么?

例如,假设我们有网站 RedBlueGreen(等等)。它们的 HTML 可能不同,但功能相同。

之前在一个解决方案中,我们创建了一个项目 Colour,其中包含该项目的通用版本。 RedBlueGreen 拥有自己的项目,并且每个技术页面都设置为在 Colour。 (也就是说,各个实现没有唯一的 C# - 所有代码文件都会被删除)。

然而,这种方法导致我们最终得到多个单独的实现 dll,这些实现 dll 几乎什么都不做,而且像 javascript、css 和常见图像之类的其他内容也会在项目中重复。

理想情况下,我们希望能够单独运行每个项目,而源安全共享似乎总是一个糟糕的主意。

有更好的方法吗?

编辑:忘记提及,所有业务逻辑/数据访问均由共享业务层项目处理,因此所有代码都是单独和共享的。

Given multiple websites all running the same sourcecode, what's the best/most maintainable way to organise these into projects within visual studio?

For example, say we have websites Red, Blue, and Green (etc). Their HTML may be different, but they are a functionally the same.

Previously in one solution we have created one project Colour, which contains a generic version of the project. Red, Blue, and Green get their own project, and each technical page is set to use the C# in Colour. (That is, there's no unique C# for the individual implementations - all code files get removed).

However, this approach leads us to ending up with multiple individual implementation dll's that do next to nothing, and also Other Stuff like javascript, css, and common images get duplicated accross projects.

Ideally we'd like to be able to run each project in isolation, and sourcesafe sharing always seems like a terrible idea.

Is there a Better Way?

edit: forgot to mention, all business logic / data access is handled by a shared Business Layer project, so all the code for that is separate and shared.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

め可乐爱微笑 2024-09-23 05:44:34

将共享代码打包到类库中。这将处理数据层、业务逻辑和其他一些辅助例程。我的经验是,它对具有相同基础的项目有很大帮助。

你的项目是红色、绿色和蓝色,如果它们不同,那么它们必须分开。你无法真正规避这一点。我个人的方法是在你忘记之前立即将其中一项所做的更改引入到所有其他更改中。这对我来说效果很好。

Pack the shared code into a class library. That'll take care of the data layer, business logic and some other auxiliary routines. My experience is that it helps a great deal with projects having the same foundation.

Your projects Red, Green and Blue, if they are different then they have to be kept apart. You can't really circumvent that. My personal approach is to immediately introduce a change made in one into all others before you forget it. That has worked fine for me.

淡淡の花香 2024-09-23 05:44:34

我建议您使用 ASP.NET 的 MVP 模式。这样,您就可以拥有一个包含模型和演示器的类库项目,这些项目将被多个包含视图的 ASP.NET 应用程序引用,当然还有静态资源,例如 JS、CSS、可能特定于每个站点的图像。当然,如果您想在 Web 应用程序之间共享静态资源,您可以将它们放入一个公共位置,以便从那里引用它们(就像 sstatic.net 所做的那样)。

所以你的解决方案可能如下所示:

NameOfProject.sln
    |
    |-- NameOfProject.Presenters
    |
    |-- Web Application 1
    |
    |-- Web Application 2
  .....
    |-- Web Application n

I would recommend you using the MVP pattern with ASP.NET. This way you could have a single class library project containing the models and the presenters which would be referenced by multiple ASP.NET applications containing the views and of course static resources such as JS, CSS, images which could be specific to each site. Of course if you want to share static resources between web applications you could put them into a common location so that they are referenced from there (like SO does with sstatic.net).

So your solution could look like this:

NameOfProject.sln
    |
    |-- NameOfProject.Presenters
    |
    |-- Web Application 1
    |
    |-- Web Application 2
  .....
    |-- Web Application n
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文