单一解决方案中的多种应用

发布于 2024-12-28 07:20:03 字数 291 浏览 1 评论 0原文

我相信这是可能的,但不确定如何解决它,我需要创建一个服务器/客户端解决方案,通常我会为服务器创建一个新的解决方案,为客户端创建一个新的解决方案,但是我希望在一个单一的解决方案中完成此操作解决方案,因为它们都使用相同的自定义类,并且真的不希望出现必须两次更改同一文件的问题。

所以问题是我可以在一个解决方案中创建多个 exe 文件吗?实现这一目标的步骤是什么。

我已经在这里搜索过,但不完全理解这个过程,所以如果有人能指出我大致正确的方向,那就太好了。 :)

使用 C Sharp 和 Windows 窗体的 VS2010

I believe this is possible but unsure how to go around it, I need to create a server/client solution, normally I would create a new solution for the server and a new one for the client however I am looking to do this within a single solution as they would both be using the same custom classes and don't really want the issue of having to change the same file twice.

So the question is can I create multiple exe's within a single solution and what are the steps to achieve this.

I have searched on here but don't fully understand the procedure so if someone can point me in the general right direction it would be great. :)

VS2010 using C Sharp and Windows Forms

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

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

发布评论

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

评论(7

独留℉清风醉 2025-01-04 07:20:03

请参阅 上一篇我给出的关于跨平台客户端服务器应用程序开发的答案,特别是跨多个客户端的代码重用。这也适用于您的 Winforms 客户端服务器应用程序。

正如许多答案所说,您可以构建解决方案以便共享代码,如下所示:

项目结构

解决方案
.. 通用(消息、数据合同、实用程序)
..中间件(引用Common,提供通用服务)
.. .. Server Exe(参考通用,中间件)
.. .. Client Exe(参考通用、中间件)

顶级客户端-服务器架构

跨平台应用程序堆栈

您的堆栈变成

客户:

客户端具有 Webservices/middleware 的序列化、客户端实现和

中间件:

中间件,即服务器/客户端桌面上的共享服务和数据传输实现可以是相同的。或者,您可以调用此服务。仅适用于客户端(或仅服务器)的任何特定服务应放入单独的程序集中,并仅由特定 exe(客户端或服务器)引用。即不要共享未共享的代码!

消息/数据契约:

使用我上面概述的技术在所有客户端/服务器之间共享。在您的情况下,这些可能是客户端和服务器之间共享的常见域对象

服务器:

所有业务逻辑、数据库访问和服务器端服务实现。对于数据库访问,我推荐 PetaPoco 作为一个优秀的 MicroORM。

开发和调试

是的,一个解决方案可以有多个exe,只需使用通过右键单击服务器可执行文件或客户端可执行文件来设置启动项目以调试其中之一。

如果您希望同时运行客户端和服务器,您可以从命令行运行两者,并将调试器附加到两个进程。

此致,

Please see this and this previous answer which I gave on cross-platform client server application development, specifically with code-reuse across multiple clients. This is also applicable to your Winforms client server app here.

As many answers are saying, you can structure your solution in order to share code as follows:

Project Structure

Solution
.. Common (Messages, Datacontracts, Utilities)
.. Middleware (References Common, provides common services)
.. .. Server Exe (References Common, Middleware)
.. .. Client Exe (References Common, Middleware)

Top level client-server architecture

Cross-platform application stack

Your stack becomes

Clients:

Client has serialization, client side implementations of webservices/middleware and Model-View-Presenter patterns for the view.

Middleware:

Middleware, i.e. shared services and data transport implemetation on server / client desktop can be the same. Alternatively you could call this Services. Any specific services for client only (or server only) should go in separate assemblies and referenced only by the specific exe (client or server). i.e. dont share code that isn't shared!

Messages/DataContracts:

Shared across all clients/server using the techniques I outlined above. In your case these may be common domain objects shared between client and server

Server:

All business logic, DB access and server-side service implementations. For DB Access I'd recommend PetaPoco as an excellent MicroORM.

Development and debugging

Yes, a solution can have more than one exe, simply use set Startup Project by right clicking on Server Exe or Client Exe to debug one or the other.

If you wish to run the client and server together, you can run both from the command line and attach the debugger to both processes.

Best regards,

平定天下 2025-01-04 07:20:03

首先,确保您可以在解决方案资源管理器中看到解决方案文件:

转到工具->选项。然后在项目和解决方案下确保选中始终显示解决方案

然后,在解决方案资源管理器(右上角,项目文件所在的位置)中右键单击您的解决方案(就在项目图标上方),然后单击添加->新项目


就解决方案的布局而言,您将有 3 个项目:客户端项目、服务器项目和共享类的类库项目。

您的客户端和服务器项目将引用库项目,请参阅:项目参考 (MSDN)


另请参阅:多项目解决方案 (MSDN)

First, ensure you can see the solution file in the solution explorer:

Go to Tools->Options. Then under Projects and Solutions ensure Always Show Solutions is checked.

Then, in the solution explorer (top right, where your project's files are) right click on your solution (just above your project icon) then click Add->New Project.


In terms of the layout of the solution, you'd have 3 projects, the client project, the server project, and a class library project of shared classes.

Your client and server projects would reference the library project, see: Project Reference (MSDN)


See also: Multi-Project Solutions (MSDN)

离鸿 2025-01-04 07:20:03

您可以这样做:

  1. 有一个解决方案
  2. 将三个项目添加到该解决方案中:
    1. 项目 A:服务器 exe
    2. 项目 B:客户端 exe
    3. 项目 C:包含项目 A 和 B 使用的类的类库项目。
  3. 使项目A和B参考项目C

You would do it like this:

  1. Have one solution
  2. Add three projects to the solution:
    1. Project A: The server exe
    2. Project B: The client exe
    3. Project C: A class library project containing the classes that projects A and B use.
  3. Make project A and B reference project C
離殇 2025-01-04 07:20:03

您可以右键单击解决方案资源管理器顶部的解决方案图标,然后选择添加新项目选项。

You can right click on solution icon located at the top in the solution explorer and choose add new project option.

诗笺 2025-01-04 07:20:03
  1. 将新的类库项目添加到您的解决方案中。将您的常用代码放在那里。
  2. 将您需要的多个 WinForms 项目添加到您的解决方案中。
  3. 将类库项目的引用添加到您的 winforms 项目中。
  1. Add a new Class Library project to your solution. Put your common code in there.
  2. Add as a many WinForms projects you need to your solution.
  3. Add references to the Class Library project to your winforms projects.
黯淡〆 2025-01-04 07:20:03

单个解决方案中的多个项目没有什么特别之处 - VS 2010 完全支持这一点,请参阅 http://msdn.microsoft.com/en-us/library/23x5fk78.aspx

There is nothing special about multiple project within a single solution - VS 2010 supports this fully, see http://msdn.microsoft.com/en-us/library/23x5fk78.aspx .

爱的十字路口 2025-01-04 07:20:03

您还可以将同一项目添加到多个解决方案。无需在单个解决方案中同时拥有服务器和客户端输出。

换句话说,如果您想要在服务器和客户端中使用这些项目:

Project A: CoreClasses
Project B: Entities

那么只需将它们添加到两个解决方案中即可:

 + Solution 1: Server
   +- Project A: CoreClasses
   +- Project B: Entities
   +- Project C: ServerSpecific -> output

 + Solution 2: Client
   +- Project A: CoreClasses
   +- Project B: Entities
   +- Project D: ClientSpecific -> output

在您的主干中,它看起来像:

 /trunk/
 /trunk/ProjectA/
 /trunk/ProjectB/
 /trunk/ProjectC/
 /trunk/ProjectD/
 /trunk/ClientSolution.sln
 /trunk/ServerSolution.sln

You can also add the same project to multiple solutions. There is no need to have both the server and client output in a single solution.

In other words, if these are the projects you want to use in both server and client:

Project A: CoreClasses
Project B: Entities

Then simply add them to both solutions:

 + Solution 1: Server
   +- Project A: CoreClasses
   +- Project B: Entities
   +- Project C: ServerSpecific -> output

 + Solution 2: Client
   +- Project A: CoreClasses
   +- Project B: Entities
   +- Project D: ClientSpecific -> output

In your trunk, it would look something like:

 /trunk/
 /trunk/ProjectA/
 /trunk/ProjectB/
 /trunk/ProjectC/
 /trunk/ProjectD/
 /trunk/ClientSolution.sln
 /trunk/ServerSolution.sln
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文