"Embed" 一个程序集 'A' 在多个库中,因此消费者看不到 A,但任何库都可以

"Embed" an assembly 'A' in multiple libraries, so that a consumer cannot see A, but any of the libraries can

我有一组可以独立使用(组合)的库,但它们中的每一个都共享某些我想在单个 'core' 库中定义的函数。

我不希望这些功能对消费者可见,如果我要求消费者直接引用 Core 作为先决条件,它们就会是这样。

有没有办法让每个图书馆都可以访问 Core 的单个副本,并且不会让 Core 对消费者可见?例如,如果使用了任何库,我可以以某种方式 'embed' Core,而无需在内存中拥有多个 Core 副本吗?

Lib.Core

(component-visible) class Utility
{
    int CalculateSomething(int input) { }
}

Lib.Abc

using Lib.Core;

public class Foo()
{
    public Foo(int seed)
    {
        Value = Core.Utility.CalculateSomething(seed);
    }

    public int Value { get; private set; }
}

Lib.Xyz

using Lib.Core;
...

消费者

using Lib.Abc;
using Lib.Xyz;

public class Bar
{
    public int GetValue(int seed)
    {
        return new Foo(seed).Value;
    }
}

使用 Visual Studio 您可以将 "Core" 代码文件添加为链接文件(添加 > 现有 > 添加按钮上的下拉菜单)。这将允许 "Core" 的代码编译到每个库中,并且仍然为您提供 "Core".

的单点维护

缺点是,如果您添加新功能,则必须重新编译每个引用 "Core" 文件的库。但这应该不会太糟糕 - 因为无论如何都必须编译和分发单独的程序集核心以进行更改。