单一解决方案中的多种应用
我相信这是可能的,但不确定如何解决它,我需要创建一个服务器/客户端解决方案,通常我会为服务器创建一个新的解决方案,为客户端创建一个新的解决方案,但是我希望在一个单一的解决方案中完成此操作解决方案,因为它们都使用相同的自定义类,并且真的不希望出现必须两次更改同一文件的问题。
所以问题是我可以在一个解决方案中创建多个 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(7)
正如许多答案所说,您可以构建解决方案以便共享代码,如下所示:
项目结构
顶级客户端-服务器架构
您的堆栈变成
客户端具有 Webservices/middleware 的序列化、客户端实现和
中间件,即服务器/客户端桌面上的共享服务和数据传输实现可以是相同的。或者,您可以调用此服务。仅适用于客户端(或仅服务器)的任何特定服务应放入单独的程序集中,并仅由特定 exe(客户端或服务器)引用。即不要共享未共享的代码!
使用我上面概述的技术在所有客户端/服务器之间共享。在您的情况下,这些可能是客户端和服务器之间共享的常见域对象
所有业务逻辑、数据库访问和服务器端服务实现。对于数据库访问,我推荐 PetaPoco 作为一个优秀的 MicroORM。
开发和调试
是的,一个解决方案可以有多个exe,只需使用通过右键单击服务器可执行文件或客户端可执行文件来设置启动项目以调试其中之一。
如果您希望同时运行客户端和服务器,您可以从命令行运行两者,并将调试器附加到两个进程。
此致,
As many answers are saying, you can structure your solution in order to share code as follows:
Project Structure
Top level client-server architecture
Your stack becomes
Client has serialization, client side implementations of webservices/middleware and Model-View-Presenter patterns for the view.
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!
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
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,
首先,确保您可以在解决方案资源管理器中看到解决方案文件:
转到
工具->选项
。然后在项目和解决方案
下确保选中始终显示解决方案
。然后,在解决方案资源管理器(右上角,项目文件所在的位置)中右键单击您的解决方案(就在项目图标上方),然后单击
添加->新项目
。就解决方案的布局而言,您将有 3 个项目:客户端项目、服务器项目和共享类的类库项目。
您的客户端和服务器项目将引用库项目,请参阅:项目参考 (MSDN)
另请参阅:多项目解决方案 (MSDN)
First, ensure you can see the solution file in the solution explorer:
Go to
Tools->Options
. Then underProjects and Solutions
ensureAlways 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)
您可以这样做:
You would do it like this:
您可以右键单击解决方案资源管理器顶部的解决方案图标,然后选择添加新项目选项。
You can right click on solution icon located at the top in the solution explorer and choose add new project option.
单个解决方案中的多个项目没有什么特别之处 - 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 .
您还可以将同一项目添加到多个解决方案。无需在单个解决方案中同时拥有服务器和客户端输出。
换句话说,如果您想要在服务器和客户端中使用这些项目:
那么只需将它们添加到两个解决方案中即可:
在您的
主干
中,它看起来像: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:
Then simply add them to both solutions:
In your
trunk
, it would look something like: