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
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.
If you’re working with Visual Studio, right click on the
References
menu in theProduct.Client
orProduct.Server
project, clickAdd Reference
in the popup select theProjects
tab and then add a checkmark where needed (in your caseProduct.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 soIf 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 workIf 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