如何静态链接 C# ClassLibrary 的库?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1102296/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-06 08:17:43  来源:igfitidea点击:

How to statically link libraries for a C# ClassLibrary?

c#c#-2.0

提问by Cute

I am creating a Class LLibrary in c# by using microsoft provided Dll's.

我正在使用微软提供的 Dll 在 c# 中创建一个类 LLibrary。

Now i want to statically add those Microsoft provided libraries to My Dll.How can i do this. I have simply added a reference to those Microsoft provided Dlls and creating My Dll? Is it fine or not?

现在我想将那些 Microsoft 提供的库静态添加到我的 Dll。我该怎么做。我只是添加了对 Microsoft 提供的 Dll 的引用并创建了我的 Dll?好不好?

if Microsoft provided dll is not available on other machine then my Dll may fails i need to add the libraries statically??

如果 Microsoft 提供的 dll 在其他机器上不可用,那么我的 Dll 可能会失败,我需要静态添加库?

How can i do this??

我怎样才能做到这一点??

回答by Mehrdad Afshari

There's no such thing as statically linking to another assembly in .NET. There are some third party products such as .NET linkerthat merge assemblies into one but they are unsupported.

没有静态链接到 .NET 中的另一个程序集这样的事情。有一些第三方产品(例如.NET 链接器)将程序集合并为一个,但它们不受支持。

If you have the redistribution license for that library, you can ship a copy along with your assembly. In Visual Studio you can make this happen by setting "Copy Local" to "True" in the properties window for that assembly reference.

如果您拥有该库的再分发许可证,则可以随程序集一起发送副本。在 Visual Studio 中,您可以通过在该程序集引用的属性窗口中将“Copy Local”设置为“True”来实现这一点。

回答by Marc Gravell

If the dll is not available at execution time; yes it will fail. However:

如果dll在执行时不可用;是的,它会失败。然而:

  • many Microsoft dlls are pre-installed with .NET (caveat: "client profile")
  • many of the Microsoft dlls are redistributable; so you can include them with your package
  • 许多 Microsoft dll 都预装了 .NET(警告:“客户端配置文件”)
  • 许多 Microsoft dll 是可重新分发的;这样您就可以将它们包含在您的包裹中

There isn't a linker provided in the core framework, although ILMergemay be useful.

虽然ILMerge可能有用,但核心框架中没有提供链接器。

回答by MSIL

Its not very clear what you want to achieve but it seems you are concerned that your class lib will work on some other machine or not. The thing is that the .Net framework is a free redistributable which should be installed if not present on the target machine. With the .Net framework already installed on a machine, there should be no problem as such.

不太清楚您想要实现的目标,但您似乎担心您的类库是否可以在其他机器上运行。问题是 .Net 框架是一个免费的可再发行组件,如果目标机器上不存在,则应该安装它。机器上已经安装了.Net框架,应该没有问题。

Static linking as such does not make sense in .Net other that adding an assembly reference to your project. Hope it helps

这样的静态链接在 .Net 中没有意义,除了向您的项目添加程序集引用。希望能帮助到你

回答by Kaganar