How to statically link libraries for a C# ClassLibrary?

拟墨画扇 提交于 2019-12-13 13:02:10

问题


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

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?

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

How can i do this??


回答1:


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

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.




回答2:


See discussion here and read the comments -- Jeff does provide a way.

http://blogs.msdn.com/b/microsoft_press/archive/2010/02/03/jeffrey-richter-excerpt-2-from-clr-via-c-third-edition.aspx




回答3:


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

  • 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

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




回答4:


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.

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



来源:https://stackoverflow.com/questions/1102296/how-to-statically-link-libraries-for-a-c-sharp-classlibrary

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!