Access to dll methods

后端 未结 3 1480
爱一瞬间的悲伤
爱一瞬间的悲伤 2021-01-03 16:58


I prepared some C# dll for my customer that doing some functionality.
The thing is that I use also same dll.
How can I make some methods available to him and al

相关标签:
3条回答
  • 2021-01-03 17:40

    Use a shared code base

    Simply compile two projects. One contains the source for the DLL you are providing to the customer, and the other contains all the source, which you keep for yourself.

    • Advantage: They see none of the source you want to keep for yourself, and you don't have to set up any sort of special hosting - just send them the DLL
    • Disadvantage: You have to do extra work to set up your code base to be fork-able. It might be a large development investment to do this sort of refactor.

    Provide a web service

    Provide a web service for the customer to access the code that they are allowed to access.

    • Advantage: They see none of the source at all.
    • Disadvantage: Depending on the code, it might be a lot of work (to get security up-to-snuff), and might be impossible (to get performance up to snuff). Or it might be easy, because maybe these aren't big concerns. You also have to set up dedicated hosting for this to work.

    Use the InternalsVisibleTo attribute in the shared DLL

    1. Mark those methods you want to use internal
    2. Code sign your own code that uses the DLL
    3. Code sign the shared DLL
    4. Add [assembly: InternalsVisibleTo] to the shared DLL

    See: http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute.aspx

    • Advantage: This is a very easy solution to code up
    • Disadvantage: The client will have access to the full source code, via Reflector. You could mitigate this by obfuscating your code, or setting up a licensing agreement that legally forbids them to reverse engineer your code.
    0 讨论(0)
  • 2021-01-03 17:46

    You could use the C# preprocessor directives like #define to compile two versions of the library from the same code base.

    Then ship one version to your customer, keep the other version for yourself.

    0 讨论(0)
  • 2021-01-03 17:50

    You have to compile two versions of your assembly. The version you distribute to your cutomer needs to completely exclude the methods you don't want them to access, otherwise they'll be accessible through Reflection regardless of how you "hide" them.

    (Assuming you don't want your assemblies to be signed)

    0 讨论(0)
提交回复
热议问题