.NET ShellExtension(Framework 4.5,Windows 8.1,SharpShell)不起作

本文关键字:SharpShell Windows ShellExtension Framework NET | 更新日期: 2023-09-27 18:31:30

我试图在Windows 8.1中实现一个自定义的ShellExtension。找到了非常好的SharpShell教程。

[ComVisible(true)]
[COMServerAssociation(AssociationType.AllFiles)]
public class CountExtProvider : SharpContextMenu
{
    protected override bool CanShowMenu()
    {
        //  We will always show the menu.
        return true;
    }
    protected override ContextMenuStrip CreateMenu()
    {
        //  Create the menu strip.
        var menu = new ContextMenuStrip();
        //  Create a 'count lines' item.
        var itemCountLines = new ToolStripMenuItem
        {
            Text = "Count Lines"
        };
        //  When we click, we'll call the 'CountLines' function.
        itemCountLines.Click += (sender, args) => CountLines();
        //  Add the item to the context menu.
        menu.Items.Add(itemCountLines);
        //  Return the menu.
        return menu;
    }
    private void CountLines()
    {
        //  Builder for the output.
        var builder = new StringBuilder();
        //  Go through each file.
        foreach (var filePath in SelectedItemPaths)
        {
            //  Count the lines.
            builder.AppendLine(string.Format("{0} - {1} Lines",
              Path.GetFileName(filePath), File.ReadAllLines(filePath).Length));
        }
        //  Show the ouput.
        MessageBox.Show(builder.ToString());
    } 
}

我处于Windows 8.1 RTM x64环境中,因此我在Visual Studio 2013 RC中将构建平台更改为x64。添加了一个密钥文件来签署我的 *.dll。但是,如果我想注册我的 *.dll什么也没发生:

regasm ShellExtensions.dll

命令行显示注册成功,但在上下文菜单中没有条目。我在这里做错了什么?这是否不再适用于Windows 8.1?

.NET ShellExtension(Framework 4.5,Windows 8.1,SharpShell)不起作

我在使用 regasm.exe 时遇到了同样的问题。
此外,通过regasm注册程序集时还有很多事情要提及。
例如,您必须使用x64/x86版本的regasm.exe,具体取决于您的系统。

  • x64:C:'Windows'Microsoft.NET'Framework64'v4.0.30319'regAsm.exe
  • x86:C:'Windows'Microsoft.NET'Framework'v4.0.30319'regAsm.exe

在遇到这么多问题之后,我切换到ServerManager.exe,这是SharpShell工具的一部分。可以在项目页面上下载。
用法非常简单:

  • 使用"加载服务器..."
  • 点击"安装服务器(xYZ)"
  • 之后在"注册服务器(xYZ)"

重新启动 Windows 资源管理器,您应该就完成了(不一定需要)。

我完全同意上述教程作者的观点:

服务器管理器工具

服务器管理器工具是我的首选方法安装/卸载和注册/注销,至少在开发,因为它允许您单独安装和注册步骤。它还可以让您指定您是否以 32 位或 64 位模式安装/卸载等。