简体   繁体   中英

What's the best way to provide a library to external developers in C#?

I am writing a program in C# (Visual Studio 2010) and I have a set of functions that I want to make available to other people in the form of a library. What I did was create a new project and set the project type to Class Library . I noticed that the output type is DLL.

I don't necessarily want to provide a runtime library that others can link to dynamically what I want is to provide a set of functions that others can compile their code to. (I believe in C++ this would be a .lib file.)

In C# are all libraries DLLs?

Also, what if I only want to provide (as far as source code) the function definitions but not the implementation? In C++ you would give only the .h file but what do you give them in C#?

DLL is what you would give in C#.

If you want to hide the implementation details then you can mark your classes as internal . But this would as long as the code that is using your library does not need to either reference your classes or create an instance of your classes. IF one of these is required, then there is no escaping from exposing your class implementation.

As Suhas said, the DLL is what you want to distribute.

Yes, "libraries" are DLLs. Technically they are called "assemblies" now.

Pretty much the only way I can think to do this for C# would be to have 2 assemblies. The first containing only an Interface definition whereas the second contains the actual classes that implement the interface. You could ship the first but not the second library. If going that route, I would also provide a mocked class that implements the interface for simple testing.

This would involve dynamically loading the correct assembly at runtime; which is entirely feasible. Usually through a config setting.

Going beyond that if the purpose in not providing the implementation is that you are worried about them decompiling the code, then you might look into some obfuscation tools. Not 100% effective, but it certainly dissuades a lot of junior type devs.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM