2

I've created a COM visible project and have added an Setup Wizard to the project. I've also added a Custom Actions class and have attempted to write to the registry.

Below is a sample entry for a wxs installer (which I have no experience in), how could i recreate this in C# during the install action of my custom actions class?

         <RegistryKey Root='HKCU' Key='Software\Autodesk\Structural\RSA\AddIns\{24D63E1C-E503-4EB4-9381-BF9F6A35E199}'>
      <RegistryValue Type='binary' Name='AddInsType' Value='0'/>
      <RegistryValue Type='binary' Name='Enable' Value='1'/>
      <RegistryValue Type='string' Name='File' Value='[INSTALLDIR]myaddin.dll'/>
      <RegistryValue Type='string' Name='Guid' Value='{24D63E1C-E503-4EB4-9381-BF9F6A35E199}'/>
      <RegistryValue Type='binary' Name='Guid Type' Value='2'/>
      <RegistryValue Type='binary' Name='KeepMenuGrade' Value='0'/>
      <RegistryValue Type='string' Name='KeyName' Value='{24D63E1C-E503-4EB4-9381-BF9F6A35E199}'/>

This is what I have so far in my custom actions class, using this answer. Is it correct to add the key_value_name as the same GUID as my COM dll?

namespace RegisterRoboPython
{
[RunInstaller(true)]
public partial class RegisterRoboPython : Installer
{
    public override void Install(IDictionary stateSaver)
    {
        base.Install(stateSaver);

        const string key_path = "Software\\Autodesk\\Structural\\RSA\\AddIns";
        const string key_value_name = "{5a0d8941-241c-481c-9811-2c76a91bf17c}";

        RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path, Microsoft.Win32.RegistryKeyPermissionCheck.ReadWriteSubTree);

        if (key == null)
        {
            key = Registry.LocalMachine.CreateSubKey(key_path);
        }

        string tgt_dir = Context.Parameters["TARGETDIR"];

        key.SetValue(key_value_name, tgt_dir);

    }


    public override void Commit(System.Collections.IDictionary savedState)
    {
        base.Commit(savedState);
    }

    public override void Uninstall(IDictionary savedState)
    {
        base.Uninstall(savedState);

        const string key_path = "Software\\Autodesk\\Structural\\RSA\\AddIns";
        const string key_name = "{5a0d8941-241c-481c-9811-2c76a91bf17c}";

        RegistryKey key = Registry.LocalMachine.OpenSubKey(key_path);

        if (key.OpenSubKey(key_name) != null)
        {
            key.DeleteSubKey(key_name);
        }

    }

    public override void Rollback(IDictionary savedState)
    {
        base.Rollback(savedState);
    }

    public RegisterRoboPython()
    {
        InitializeComponent();
    }
}

Edit 1: When running the installations .msi I receive the following error:

system.argumentexception FILE = DOES NOT EXIST 
IF THIS PARAMETER IS USED AS AN INSTALLER OPTION THE FORMAT MUST BE /KEY=[VALUE]

Which I am confused about as I have added /TARGETDIR = "[TARGETDIR]" to the install/commit CustomActionData properties.

So my question is, what is the correct way to register the COM dll using custom actions?

Am I on the right track? Thanks for reading, Tom

2
  • Do you have a specific question? Commented Dec 7, 2018 at 16:12
  • Sorry @RobertHarvey I should have made myself more clear, please see the edit. Commented Dec 7, 2018 at 19:27

1 Answer 1

1

Custom Action Avoidance: Please try to avoid custom actions whenever you can. Here is my propaganda against them. All you need to know is that they are error-prone. If there are built-in features that can do the same, use them instead.


Registry View: Following from this description from Microsoft, please try to use this built-in feature:

  1. Open your Visual Studio Project
  2. On the View menu, point to Editor, and then click Registry.
  3. Create keys and values as appropriate in the registry view

Please do consider sticking with some other tool for deployment. At least read the description of limitations for Visual Studio Setup Projects below.


Visual Studio Installer Projects Problems: There are some issues with Visual Studio Installer Projects that you should know about. Recommend you continue to use WiX:


Further Links:

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.