访问dll方法

发布于 2024-11-16 21:23:53 字数 101 浏览 4 评论 0原文


我为我的客户准备了一些 C# dll 来执行一些功能。
问题是我也使用相同的 dll。
我怎样才能让一些方法对他可用,而所有方法对我可用。
谢谢,

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 all methods available for me.
Thanks,

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

魂归处 2024-11-23 21:23:53

使用共享代码库

只需编译两个项目即可。一个包含您提供给客户的 DLL 源代码,另一个包含您自己保留的所有源代码。

  • 优点:他们看不到您想为自己保留的任何源代码,并且您不必设置任何类型的特殊托管 - 只需向他们发送 DLL
  • 缺点:您必须做额外的工作来设置代码库可分叉。进行这种重构可能需要大量的开发投资。

提供 Web 服务

为客户提供 Web 服务以访问他们被允许访问的代码。

  • 优点:他们根本看不到任何来源。
  • 缺点:根据代码的不同,可能需要大量工作(才能达到最佳的安全性),而且可能是不可能的(要达到最佳的性能)。或者这可能很容易,因为也许这些都不是大问题。您还必须设置专用托管才能使其工作。

使用共享 DLL 中的 InternalsVisibleTo 属性

  1. 标记要使用的方法 internal
  2. 对使用该 DLL 的自己的代码进行代码签名
  3. 对共享的代码进行签名DLL
  4. [ assembly:InternalsVisibleTo] 添加到共享 DLL

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

  • 优点:这是一个非常容易编写代码的解决方案
  • 缺点:客户端将可以访问完整的源代码,通过 Reflector。您可以通过混淆代码或制定许可协议来合法地禁止他们对您的代码进行逆向工程来缓解这种情况。

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.
天气好吗我好吗 2024-11-23 21:23:53

您必须编译程序集的两个版本。您分发给客户的版本需要完全排除您不希望他们访问的方法,否则无论您如何“隐藏”它们,都可以通过反射访问它们。

(假设您不希望对程序集进行签名)

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)

_畞蕅 2024-11-23 21:23:53

您可以使用 C# 预处理器指令就像#define一样,从相同的代码库编译两个版本的库。

然后将一个版本发送给您的客户,保留另一个版本。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文