How to forbid a .NET DLL class library to be referenced

前端 未结 4 1596
被撕碎了的回忆
被撕碎了的回忆 2021-01-14 11:42

How can I forbid dll class library to be referenced in other solutions?

4条回答
  •  無奈伤痛
    2021-01-14 12:13

    You can make some dll class methods to fail if it is not used by your own main program.

     Assembly main = System.Reflection.Assembly.GetExecutingAssembly();
    
     if (main.FullName != .....)
         throw new NotSupportedException();
    

    or

     if (IsSignedWith(main, myCompanysX509Certificate))
         throw new NotSupportedException();
    

提交回复
热议问题