Question

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

Was it helpful?

Solution

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,

OTHER TIPS

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)

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

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

  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.

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:

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
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top