[英]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:在我的公司,我们正在创建 C# 客户端/服务器应用程序,如下所示:
We create three project inside one single Visual Studio solution:我们在一个 Visual Studio 解决方案中创建了三个项目:
The "General" project contains functionality, to be used by both client and server parts. “General”项目包含可供客户端和服务器部分使用的功能。
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.为了完成这项工作,我们编译“Product.General”并将二进制文件添加为对“Product.Client”和“Product.Server”项目的引用。
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提前致谢
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 ).如果您正在使用 Visual Studio,请右键单击
Product.Client
或Product.Server
项目中的References
菜单,单击Projects
选项卡弹出 select 中的Add Reference
,然后在需要的地方添加复选标记(在您的情况下为Product.General
)(见vivek nuna的回答)。 I assume it's basically the same in something liked Rider.我认为它在类似 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如果您不使用 Visual Studio,而是使用新的 .NET(不是.NET 框架),您可以像这样使用
dotnet
cli 工具
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如果您使用的 shell 的工作目录包含一个 .csproj 文件,您可以省略第一个
path/to/*.csproj
,所以这样做应该可以
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如果您没有使用 Visual Studio 或其他一些 IDE 并且由于某种原因无法使用 dotnet cli 工具,那么您可以手动编辑 .csproj 文件,如下所示
<ItemGroup>
<ProjectReference Include="path/to/Product.General.csproj" />
</ItemGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.