4

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

Neo
  • 2,305
  • 4
  • 36
  • 70
  • 1
    Just add as many projects as you want and build your solution. – Matías Fidemraizer Jan 23 '12 at 16:19
  • I think before one can trully answer your question you need to be more specific as to what type of application this Client Server will do.. is it a traditional FAT Client, Thin Client, WPS,etc.. then specify what the app is suppose to do and one can suggest a valid soulution from there.. – MethodMan Jan 23 '12 at 16:25
  • The system should basicly output two executable files, the install using ISS would then pick the correct one to install, it is a simple support desk software so there is a program for the clients to have installed in their notification area, and another one on the companies machines so when a new ticket is raised it pops up a notification. – Neo Jan 23 '12 at 16:31
  • Do you mean threading or threat surface analysis, @mekici – Tetsujin no Oni Jan 23 '12 at 16:41
  • Are you looking for [Multi-project solutions](http://msdn.microsoft.com/en-us/library/23x5fk78.aspx)? – gabsferreira Jan 23 '12 at 16:19

7 Answers7

10

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,

Community
  • 1
  • 1
Dr. Andrew Burnett-Thompson
  • 20,980
  • 8
  • 88
  • 178
  • @Neo thank you! I hope it wasn't overkill. I got the impression from your question you were also unsure of general client/server architecture not just project setup. The project part is actually very easy in VS2010. Just add multiple Exe's and use the Set Startup Project. The difficult part is how to partition your code to enable efficient sharing and re-use of key logic, classes etc. My advice, don't create too many projects. I worked on one app recently with 97 projects in a client/server environment :( That and use interfaces / abstractions and above all **Dependency Injection** – Dr. Andrew Burnett-Thompson Jan 23 '12 at 16:41
  • Hi Andy, nope not overkill at all no such thing in my book :) I have integrated several client server apps using a custom php api I created so the integration isn't an issue it was just mainly the VS side of things as its not the most friendly of environments! I am interested in several of the items you meantioned in your post, MVP? MVVM? Also do you have further information on PetaPoco as it sounds interesting. – Neo Jan 23 '12 at 16:45
  • @Neo apologies a lot of the above is a re-hash of previous questions (as disclaimed). I will edit out MVVM as it is not applicable in your case for winforms. MVP is `Model View Presenter` which I suggest you look up as a best practice for developing GUI code in winforms. Petapoco is a C# Object Relational Mapping library - 1500 lines - its micro but its very powerful. If your server is implemented in php this will also not be applicable – Dr. Andrew Burnett-Thompson Jan 23 '12 at 16:48
2

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)

George Duckett
  • 31,770
  • 9
  • 95
  • 162
1

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
Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
1

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

user1163459
  • 128
  • 4
1
  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.
Daniel A. White
  • 187,200
  • 47
  • 362
  • 445
1

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 .

Yahia
  • 69,653
  • 9
  • 115
  • 144
1

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
vgru
  • 49,838
  • 16
  • 120
  • 201