c++windowswinapiwindows-shell

Error while installing context menu based on IExplorerCommand


I am trying to install a context menu handler written in C++ that implements IExplorerCommand. For installation, I use the instructions which are specified in this repository:

https://github.com/microsoft/AppModelSamples/tree/master/Samples/SparsePackages

Everything is going well, except for the last step. When I run the application which should install the msix package, the manifest of which contains information about the context menu, I get the following error:

A fatal error occurred. The required library hostfxr.dll could not be found. If this is a self-contained application, that library should exist in [C:\Users\Username\Desktop\windows-menu\bin]. If this is a framework-dependent application, install the runtime in the global location [C:\Program Files\dotnet] or use the DOTNET_ROOT environment variable to specify the runtime location or register the runtime location in [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x64\InstallLocation].

Why does this error occur, and how can I fix it? I am using Windows 10.


UPDATE

I copied the hostfxr.dll file to the bin folder, but after that I got the following output:

Architecture: x64 Framework: 'Microsoft.NETCore.App', version '3.1.0' (x64) .NET location: C:\Users\Username\Desktop\windows-menu\bin\ No frameworks were found.

Does installing a context menu really require .NET? What if my program is used by a user who does not have .NET on their computer?


Solution

  • Because the context menu installer is written in C#, .NET components must be installed for the program to run.

    In addition, if installing on a fresh machine, the Microsoft Visual C++ Redistributable must be installed to provide the C++ (MSVC) runtime libraries.