[英]Copy service reference from one project to another project in same solution
[英]How to include functionality from one project into another in the same solution?
在我的公司,我们正在创建 C# 客户端/服务器应用程序,如下所示:
我们在一个 Visual Studio 解决方案中创建了三个项目:
“General”项目包含可供客户端和服务器部分使用的功能。
为了完成这项工作,我们编译“Product.General”并将二进制文件添加为对“Product.Client”和“Product.Server”项目的引用。
在我们的源代码中,如下所示:
在“通用”项目中:
namespace Product.Customer.Configuration
{
public class SettingManager
{
...
}
}
在“服务器”项目中:
using Product.Customer.Configuration;
...
var settingManager = ...<SettingManager>();
我不喜欢,因为除此之外,您首先需要编译“常规”部分,然后才能开始处理“客户端”或“服务器”项目。
我怎样才能让这样的系统工作,而不需要将编译的二进制文件添加到项目的引用中?
提前致谢
如果您正在使用 Visual Studio,请右键单击Product.Client
或Product.Server
项目中的References
菜单,单击Projects
选项卡弹出 select 中的Add Reference
,然后在需要的地方添加复选标记(在您的情况下为Product.General
)(见vivek nuna的回答)。 我认为它在类似 Rider 的东西中基本相同。
如果您不使用 Visual Studio,而是使用新的 .NET(不是.NET 框架),您可以像这样使用dotnet
cli 工具
dotnet add path/to/Product.Client.csproj reference path/to/Product.General.csproj
如果您使用的 shell 的工作目录包含一个 .csproj 文件,您可以省略第一个path/to/*.csproj
,所以这样做应该可以
cd Product.Client
dotnet add ../Product.General/Product.General.csproj
如果您没有使用 Visual Studio 或其他一些 IDE 并且由于某种原因无法使用 dotnet cli 工具,那么您可以手动编辑 .csproj 文件,如下所示
<ItemGroup>
<ProjectReference Include="path/to/Product.General.csproj" />
</ItemGroup>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.