DEV Community

Creating Shell Extensions in .NET 8 with SharpShell

issam boutissante on June 03, 2024

In this blog, I'll walk you through creating a Windows shell extension using the SharpShell library in .NET 8. SharpShell is a popular library for ...
Collapse
 
bd9000 profile image
David Nuss

I copied verbatim what you did, and it works from VS, however, nothing shows up outside (no dropdown menu item called "Simple Extension Action" is there).
I did this after doing a release build and copying the following files over to a different folder:

06/18/2024 08:12 PM 1,049 Register.bat
05/17/2024 03:09 PM 184,320 SharpShellNet8Demo.comhost.dll
06/18/2024 08:15 PM 45,552 SharpShellNet8Demo.deps.json
06/18/2024 08:15 PM 7,168 SharpShellNet8Demo.dll
06/18/2024 08:15 PM 13,752 SharpShellNet8Demo.pdb
06/18/2024 08:15 PM 493 SharpShellNet8Demo.runtimeconfig.json
06/18/2024 08:13 PM 1,056 Unregister.bat

Do I need all 89 files in the Release output for this to work?
Is there a way to eliminate a lot of these completely unused dlls in the output (like System.Speech.dll)?

Guess I need to learn C++ for Windows (a 17MB dll is a bit huge and redundant)

Collapse
 
bd9000 profile image
David Nuss

Looks like these are all the files you actually need to run (whew!), so if you wrote an installer for say, distributing to regular people, you could extract from a zip to a folder, then run register.bat.
Nice work, by the way!

06/18/2024 08:12 PM 1,049 Register.bat
11/06/2019 10:18 PM 451,072 SharpShell.dll
05/17/2024 03:09 PM 184,320 SharpShellNet8Demo.comhost.dll
06/18/2024 08:45 PM 45,750 SharpShellNet8Demo.deps.json
06/18/2024 08:45 PM 6,656 SharpShellNet8Demo.dll
06/18/2024 08:45 PM 493 SharpShellNet8Demo.runtimeconfig.json
10/31/2023 07:59 AM 294,160 System.ComponentModel.Composition.dll
06/18/2024 08:13 PM 1,056 Unregister.bat

Collapse
 
issamboutissante profile image
issam boutissante • Edited

Yes, you will need to include all of these DLLs; otherwise, you will encounter assembly not found exceptions. Unfortunately, because this is a class library, you can't use trimming to reduce the size. Therefore, you will need to have all the files.

Alternatively, you could create a console app and use it as a trimming helper for your library by referencing it there (I haven't tried this, but it might work). This is one of the cons of using .NET 8 with SharpShell. As you mentioned, C++ is a good option, but the ease of use with .NET SharpShell is worth considering despite the large size. Ultimately, it depends on your use case.

For example, in my case, we have many shell extensions, so they share all the DLLs. We also have .NET desktop apps that use the same DLLs, and we have them all centralized in one folder. So, the DLLs are already there; I only need to add my shell DLL and the SharpShell DLL. For the others, they are already there because they are being used by other apps.

Thank you for your Feedback David, and if you find any solution for reducing the size, hope you share it with us!


I tried to use only the files you mentioned @bd9000 and it's working perfectly with just less that 1MB

that's great!

Collapse
 
mike_rdz_a920f49809a53998 profile image
Mike Rdz

How to add icons?

Collapse
 
issamboutissante profile image
issam boutissante

Actually I didn't try the icons, but I will try to add an icon using the Image property and will keep you updated!

Collapse
 
jordi_arenasvigo_221021a profile image
Jordi Arenas Vigo

It seems to fail. I've tryied.

Collapse
 
chenard1974 profile image
CHENARD1974

Hi Issam,
I created the project as you explained, and everything worked. The problem is that I can't add a resource of type Image, and I also have the following problem: The package 'SharpShell 2.7.2' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8, .NETFramework,Version=v4.8.1' instead of the project's target framework 'net8.0-windows7.0'. This package may not be fully compatible with your project.

Collapse
 
jordi_arenasvigo_221021a profile image
Jordi Arenas Vigo

Have you try with another use case, for example, SharpIconOverlayHandler in .NET 8? I have tried and I have a lot of problems with registration.

Collapse
 
scott_ipclis_ee551d525 profile image
Scott (IPC) Lis

The SharpIconOverlayHandler is not registering. It seems to convert ok, but something is missing. The Context Menu works fine.

Collapse
 
chaimae_mazzouz profile image
Chaimae Mazzouz

great explanation, thanks a lot, that was helpful

Collapse
 
issamboutissante profile image
issam boutissante

Thank you :)