Search code examples
c#windowscontextmenumsix

How to add a new command for a new application in context menu on windows 11 File Explorer


I am developing a new application for windows (I am now running it on windows 11), I need, for the features I wanna implement, to create a new entry in windows explorer context menu. As I checked out I do need to make an installation package and indeed I am using the MSIX-packaged app to wrap my application. Following this path I found a way to extend the context menu directly on the Microsoft documentation: https://learn.microsoft.com/en-us/windows/apps/desktop/modernize/integrate-packaged-app-with-file-explorer However nor my code nor the examples brought by Microsoft itself seem to work properly. I assume it is due to the fact I am developing and running the application on Windows 11 and this method is or incomplete or not working on that Windows version.

Here is the script on the manifest which should add a new entry in the context menu as the app is running. It is light modification of the same in the Microsoft documentation: I added the <uap10:FileType>*</uap10:FileType> part for making any extensions to be available for the new context menu entry.

<Extensions>
    <uap3:Extension Category="windows.fileTypeAssociation">
      <uap3:FileTypeAssociation Name="anyfile" Parameters="&quot;%1&quot;">
        <uap:SupportedFileTypes>
          <uap:FileType>.foo</uap:FileType>
          <uap10:FileType>*</uap10:FileType>
        </uap:SupportedFileTypes>
        <uap2:SupportedVerbs>
          <uap3:Verb Id="Resize" Parameters="&quot;%1&quot;">Resize file</uap3:Verb>
        </uap2:SupportedVerbs>
      </uap3:FileTypeAssociation>
    </uap3:Extension>
    <com:Extension Category="windows.comServer">
      <com:ComServer>
        <com:SurrogateServer DisplayName="ContextMenuSample">
          <com:Class Id="CC19E147-7757-483C-B27F-3D81BCEB38FE" Path="ExplorerCommandVerb.dll" ThreadingModel="STA"/>
        </com:SurrogateServer>
      </com:ComServer>
    </com:Extension>
    <desktop4:Extension Category="windows.fileExplorerContextMenus">
      <desktop4:FileExplorerContextMenus>
        <desktop5:ItemType Type="Directory">
          <desktop5:Verb Id="Command1" Clsid="CC19E147-7757-483C-B27F-3D81BCEB38FE" />
        </desktop5:ItemType>
      </desktop4:FileExplorerContextMenus>
    </desktop4:Extension>
    <uap:Extension Category="windows.protocol">
      <uap:Protocol Name="protocolname"/>
    </uap:Extension>
  </Extensions>

Solution

  • It works properly also on Windows 11 (v 10.0.22621.0)! The question itself was not really appropriated here, but I hope this related answer can still save some time to someone else. To make it work I simply had to go into the properties of the package and of the referenced application and, from there, resolve any found conflicts about minimum and the target version, and then downloading the proper SDK, having chosen as main target the v. 10.0.22621.0.

    properties menu enter image description here

    Thanks to you all as always