Use NuGet to add the package to your project.
Installing a Chrome Native Messaging Host manually is an easy process: you need to create a manifest file, copy the file to the proper location, and create a registry entry (Windows only). Learn more about the installation process on the official documentation page for native messaging.
Using Chrome.NativeMessaging.Installer
, the process is even easier. The following code snippet will install the same manifest as the one on the above link:
var manifest = new NativeMessagingHostManifest
{
Name = "com.my_company.my_application",
Description = "My Application",
Path = @"C:\Program Files\My Application\chrome_native_messaging_host.exe",
AllowedOrigins = new []
{
"knldjmfmopnpolahpmmgbagdohdnhkik"
}
};
// System.IO.Abstractions
var fs = new FileSystem();
var installer = NativeMessagingHostInstallerFactory.CreateInstaller(fs);
installer.Install(manifest);
The manifest properties have the same rules as described in the official documentation, and the object is validated before the installation happens. You may notice that the above code snippet does not set the Type
property - that's because it has only one possible value, therefore it is constant.
The Install
method returns the paths to which the manifest file was written to.
Note: the installer does not copy or deploy the actual native messaging host executable. It only creates the manifest and sets it up accordingly for Chrome to find. Your installation logic needs to implementent deployment and set the correct path in the manifest.
Removing the Chrome Native Messaging Host is even easier. If you were to do this manually, all you'd need to do is delete the manifest file, and on Windows, also delete the registry key.
The code is identical to the above, but you call Uninstall
on the installer object instead of Install
:
installer.Uninstall(manifest);
Note: the above action does not remove any of the native messaging host files, it only deletes the manifest and registry keys (if applicable).
Please refer to the XML documentation for more details.
The package is designed to be platform independent - however, the installer is currently only implemented for Windows. There are plans to implement the Linux and OS X version as well.