skip to Main Content

In my company, we are creating C# client/server applications as follows:
We create three project inside one single Visual Studio solution:

  • Product.General
  • Product.Client
  • Product.Server

The "General" project contains functionality, to be used by both client and server parts.

In order to make this work, we compile the "Product.General" and add the binary as a reference to the "Product.Client" and "Product.Server" projects.

In our source code, this looks as follows:

In the "General" project:

namespace Product.Customer.Configuration
{
    public class SettingManager
    {
        ...
    }
}

In the "Server" project:

using Product.Customer.Configuration;
...
var settingManager = ...<SettingManager>();

I don’t like, because amongst other first you need to get the "General" part compiled before you can even start working on your "Client" or "Server" project.

How can I get such a system to work, without needing to add compiled binaries into projects’ references?
Thanks in advance

2

Answers


  1. You should add the reference with Add Project Reference and then select the General Project like this. and whenever you are making changes just do Ctrl+Shift+B to build the solution.

    enter image description here

    enter image description here

    Login or Signup to reply.
  2. If you’re working with Visual Studio, right click on the References menu in the Product.Client or Product.Server project, click Add Reference in the popup select the Projects tab and then add a checkmark where needed (in your case Product.General) (see vivek nuna’s answer). I assume it’s basically the same in something liked Rider.

    If you’re not using Visual Studio, but are using the new .NET (not .NET Framework) you can use the dotnet cli tool like so

    dotnet add path/to/Product.Client.csproj reference path/to/Product.General.csproj
    

    If the working directory of the shell your using contains a .csproj file, you can omit the first path/to/*.csproj, so doing something like this should work

    cd Product.Client
    dotnet add ../Product.General/Product.General.csproj
    

    If you’re not using Visual Studio or some other IDE and for some reason can’t use the dotnet cli tool, then you can manually edit the .csproj files, like so

    <ItemGroup>
      <ProjectReference Include="path/to/Product.General.csproj" />
    </ItemGroup>
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search