如何使.NET类库可链接(无DLL) [英] How to make .NET class library linkable (no DLL)

查看:23
本文介绍了如何使.NET类库可链接(无DLL)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在C ++的过去"时代,您有两种选择来创建(类或其他)库-DLL或可静态链接.

In the "old days" of C++, you had two options for creating a (class or otherwise) library - DLL or static linkable.

我的解决方案中有一些项目是共享"库,供同一解决方案中的两个或多个其他项目使用.现在,它们被导出为DLL,然后被忠实地复制到使用它们的每个实际可执行文件的"bin"文件夹中.

I have some projects in my solution that are "shared" libraries to be used by two or more other projects in the same solution. Right now, they are being exported as DLLs which are then faithfully copied to the 'bin' folder of every single one of the actual executables that are using them.

我讨厌看到所有这些DLL在运行(对于我的库和Nuget提供的第三方库),如果有.NET,我实际上更喜欢将它们链接"到可执行文件中这样做的方式(除了将代码放在单独的文件夹中并将其包括在所有项目中,这对于通过查看解决方案资源管理器使其变得很明显而言是很丑陋的).

I'm tired of seeing all of these DLLs running around (for both my libraries and Nuget-provided third-party libraries) and I would actually prefer to "link them in" to the executables, if there is a .NET way of doing so (short of just putting the code in separate folders and including them in all of the projects, which is kind of ugly with respect to making it obvious what is going on in by inspection of the Solution Explorer).

那么-链接"库是否已死于.NET?如果是这样,那么至少有一种注册程序集的方式(我们过去用于注册COM DLL的方式),以便在解决方案中安装了多个可执行文件的情况下,只有DLL的一个副本.在多个位置复制相同的DLL的方法?

So - is "linking" libraries dead and gone with .NET? If so, is there at least a way of registering assemblies (the way we used to register COM DLLs in the past) so there is only a single copy of the DLL in cases where more than one of the executables in the solution is installed instead of having the same DLLs replicated in multiple places?

推荐答案

AFAIK .NET(和CLR)没有静态链接库的概念.

AFAIK .NET (and the CLR) don't have the notion of statically linked libraries.

正如SLaKs指出的那样,有一些工具可以欺骗IL,但是您需要权衡这种增加的复杂性所带来的成本,以仅仅减少浮动的DLL文件的数量.真的那么重要吗?

As SLaKs points out, there are tools to fool with the IL, but you'd need to weigh the cost of this added complexity to the benefit of simply reducing the number of DLL files floating around; is it really that important?

相反,至少从Visual Studio 2015开始,您可以使用共享项目".

Instead, you can use a "Shared Project", at least since Visual Studio 2015.

它只是普通代码/资源的可参考容器,与您要实现的结果非常接近.

It simply acts as a reference-able container for common code/resources, which is pretty close to the result you're looking to achieve.

请参阅"

根据SLaK,另请参见"库的静态链接在C#.NET上创建".

As per SLaKs, also see "Static Linking of libraries created on C# .NET".

这篇关于如何使.NET类库可链接(无DLL)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆