简体   繁体   中英

How to include functionality from one project into another in the same solution?

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

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 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM