我在 C# 中有一个类库项目,它只引用 System
程序集;它编译得很好,但显然不能单独使用,因为它只是一个类库。
使用该库的项目有更多的引用程序集。特别是,它们似乎都包括 System.Core
和 Microsoft.CSharp
等。所有项目现在都运行良好,但我不禁想知道它是否只是因为库所需的 DLL 是封闭项目的子集,或者因为 .NET 程序集在 GAC 中并且在传递需要时神奇地找到了。
假设一个 hello world 程序(即没有 linq、没有 xml、没有配置等),可接受的最小引用集是多少?
库项目是否还应该显式引用 System.Core
和 Microsoft.CSharp
?这些听起来很重要。
=====
编辑:
Visual Studio 中的类库项目模板在默认情况下始终包含 System.Core
和 Microsoft.CSharp
,即使删除它们也是如此似乎总是没问题。这就是为什么我想知道它们是否被隐式引用。
最佳答案
What is the minimum acceptable reference set assuming a hello world program
这个:
// HelloWorld.cs
namespace HelloWorld
{
class Program
{
static void Main()
{
System.Console.WriteLine("Hello, world!");
}
}
}
将仅依赖于 mscorlib。以这种方式编译它:
csc.exe HelloWorld.cs
关于C#项目最小引用集,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16563321/