【问题标题】:SharpShell server .dll NOT signedSharpShell 服务器 .dll 未签名
【发布时间】:2016-03-14 15:09:36
【问题描述】:

我需要开发引用其他一些自定义程序集的 Shell 上下文菜单扩展...我不想为这些自定义程序集分配强名称键!

我遵循的guide 使用 SharpShell 项目并说明了如何签署(但没有解释为什么)程序集......这是我的问题:如果我签署我的最终 .dll,那么我有很多在我的项目构建阶段出错,因为我的项目引用的某些程序集没有强命名(“引用的程序集没有强名称”)。

一般来说,在谷歌上搜索 C# Shell 扩展实现,我发现所有最好的教程都在最终程序集上签名......这是强制性的吗?

如果不对程序集进行签名,ServerManager.exe 将返回此错误:“The file 'XYZ.dll' is not a SharpShell Server”。

【问题讨论】:

    标签: c# shell sharpshell


    【解决方案1】:

    我的烦恼终于解决了……通过 NuGet 获得的 SharpShell.dll 文件是 ServerManager.exe 的不同版本。 卸载 SharpShell NuGet 包并直接引用您在 ServerManager 文件夹中找到的 SharpShell.dll 是我的解决方案!

    另外,我正在看文章之间的cmets...请阅读this问题。

    【讨论】:

      【解决方案2】:

      您不需要使用旧的 DLL。 请直接使用此代码,不要使用ServerManager.exe。

      private static ServerEntry serverEntry = null;
              public static ServerEntry SelectedServerEntry
              {
                  get
                  {
                      if (serverEntry == null)
                          serverEntry = ServerManagerApi.LoadServer("xxx.dll");
                      return serverEntry;
                  }
              }
      
      public static ServerEntry LoadServer(string path)
              {
                  try
                  {
                      //  Create a server entry for the server.
                      var serverEntry = new ServerEntry();
      
                      //  Set the data.
                      serverEntry.ServerName = Path.GetFileNameWithoutExtension(path);
                      serverEntry.ServerPath = path;
      
                      //  Create an assembly catalog for the assembly and a container from it.
                      var catalog = new AssemblyCatalog(Path.GetFullPath(path));
                      var container = new CompositionContainer(catalog);
      
                      //  Get the exported server.
                      var server = container.GetExport<ISharpShellServer>().Value;
      
                      serverEntry.ServerType = server.ServerType;
                      serverEntry.ClassId = server.GetType().GUID;
                      serverEntry.Server = server;
      
                      return serverEntry;
                  }
                  catch (Exception)
                  {
                      //  It's almost certainly not a COM server.
                      MessageBox.Show("The file '" + Path.GetFileName(path) + "' is not a SharpShell Server.", "Warning");
                      return null;
                  }
              }
      

      安装代码:

      ServerRegistrationManager.InstallServer(SelectedServerEntry.Server, RegistrationType.OS64Bit, true);
      

      注册码:

      ServerRegistrationManager.RegisterServer(SelectedServerEntry.Server, RegistrationType.OS64Bit);
      

      【讨论】:

        猜你喜欢
        • 2012-12-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-03-17
        • 2010-09-13
        • 2012-08-23
        • 2021-08-19
        • 1970-01-01
        相关资源
        最近更新 更多