22 Replies Latest reply on Nov 15, 2016 1:20 PM by Christian Chu

    Add-in installer with Visual Studio 2010

    Jose Correa

      How can I create a SolidWorks add-in’s installer with Visual Studio 2010 to distribute my add-in to another computer that does not have VS installed?

      I have followed the SolidWorks API help with no success, maybe there is something that I am not doing or doing wrong.

       

      Here are the steps that I followed:

      http://help.solidworks.com/2015/English/api/sldworksapiprogguide/Miscellaneous/Create_Setup_Project_to_Distribute_SolidWorks_Add-in.htm?id=5e152c0abbef41ad99e957ec76cb2335

        • Re: Add-in installer with Visual Studio 2010
          Joe Morton

          I'm having the same issue. I'm using Visual Studio 2015. I had to download Microsoft Visual Studio 2015 Installer Projects to be able to create the installer, but it doesn't seem to be working.

            • Re: Add-in installer with Visual Studio 2010
              Colin Poushay

              I was having problems with this as well but figured out how to install it. Assuming that you are able to install the files (your add-in DLL, and any dependent libraries). you then need to register the assembly. To register the assembly, open up the command prompt, then type

              "cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319" and hit enter, then type "RegAsm.exe C:\SolidWorksAddIns\lib\SWAddIn.dll /codebase"

               

              You will need to adjust this command based on what version of .NET framework your add-in is using. Since I used .NET Framework 4, I navigated to the directory \v4.0.30319 , if your project was in .NET framework 3 the directory would be \v3xxxxxx.

               

              The path after "RegAsm.exe" is the path to where the addin dll is installed on the computer.

               

               

              Checkout the attached image to see what a successful registration looks like. If you are still having problems, reply here and I will check back later.

               

              success.png

                • Re: Add-in installer with Visual Studio 2010
                  Joe Morton

                  Thank you! That worked!

                  I want to distribute my add-in to my coworkers. Do you have any idea of how to include this process as part of the install file? I think I can write a vb script and include it as a custom action in the install file, but that seems like a pretty clunky solution.

                    • Re: Add-in installer with Visual Studio 2010
                      Jesse Rosalia

                      You can use the instructions provided in the original post (https://forum.solidworks.com/external-link.jspa?url=http://help.solidworks.com/2015/English/api/sldworksapiprogguide/Miscellaneous/Create_Setup_Project_to_Distribute_SolidWorks_Add-in.htm?id=5e152c0abbef41ad99e957ec76cb2335), but it may not work out of the box.  Depending on the version of Visual Studio you are using, and the version of SOLIDWORKS you are targeting, you may have to handle registration yourself.  This is because in some versions of Visual Studio, the built in installer project produces a 32-bit installer binary, which will use the 32-bit .NET registration tools, which modify the 32-bit registry.  If you are targeting a 64-bit version of SOLIDWORKS, it will not be able to find your registry entries.  This issue popped up for me because I am using Visual Studio 2015 community edition with the Visual Studio 2015 Installer Projects pack installed, and I was targeting Solidworks 2014 64-bit edition and SOLIDWORKS 2016 (which is all 64 bit).

                       

                      To get around this, add an Installer Class called clsRegisterDll (in clsRegisterDll.cs) to your add-in project, and paste in the following code:

                          [RunInstaller(true)]
                          public partial class clsRegisterDll : System.Configuration.Install.Installer {
                              public clsRegisterDll() {
                                  InitializeComponent();
                              }
                      
                      
                              [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
                              public override void Commit(System.Collections.IDictionary savedState) {
                                  base.Commit(savedState);
                                  // Get the location of regasm
                                  string regasmPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";
                                  // NOTE: Needed because this is likely a 32 bit install program.
                                  regasmPath = regasmPath.Replace("Framework", "Framework64");
                                  // Get the location of our DLL
                                  string componentPath = typeof(clsRegisterDll).Assembly.Location; 
                                  // Execute regasm
                                  System.Diagnostics.Process.Start(regasmPath, "/codebase \"" + componentPath + "\"");
                              }
                      
                      
                              [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
                              public override void Install(System.Collections.IDictionary stateSaver) {
                                  base.Install(stateSaver);
                              }
                      
                      
                              [System.Security.Permissions.SecurityPermission(System.Security.Permissions.SecurityAction.Demand)]
                              public override void Uninstall(System.Collections.IDictionary stateSaver) {
                                  base.Uninstall(stateSaver);
                      
                      
                                  // Get the location of regasm
                                  string regasmPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";
                                  regasmPath = regasmPath.Replace("Framework", "Framework64");
                                  // Get the location of our DLL
                                  string componentPath = typeof(clsRegisterDll).Assembly.Location;
                                  // Execute regasm
                                  System.Diagnostics.Process.Start(regasmPath, "/unregister \"" + componentPath + "\"");
                              }
                          }
                      }
                      

                       

                      Then, in your installer project, change the "Register" property for the "Primary output from ..." item (which will be an item in your project after you tell it to use your add-in project's primary output) to vsdrpDoNotRegister, and then right click on the installer project, select View -> Custom Actions, and define custom actions for Install, Commit, and Uninstall.  To define a custom action, right click on each of those folders, and select "Add Custom Action".  In the dialog that pops up, navigate into "Application Folder" and select "Primary output from ...".  Then, build your installer, and test it out.

                      • Re: Add-in installer with Visual Studio 2010
                        roberto gennari

                        I use Inno Setup Compiler, is a easy and free programme.

                        It have a wizard method for create a installation pack, at the end of the code I add this code for register the addin,

                         

                        [Run]

                        Filename: "C:\xxx\Register_dll.bat"; Parameters: "/x"

                         

                         

                        The Register_dll is a file ".bat" where there is  the code:

                        "cd C:\Windows\Microsoft.NET\Framework64\v4.0.30319" and hit enter, then type "RegAsm.exe C:\SolidWorksAddIns\lib\SWAddIn.dll /codebase"

                         

                        Thanks

                        Roberto

                  • Re: Add-in installer with Visual Studio 2010
                    Michael Spens

                    Hi Jose,

                         Try adding the registry content to your VS 2010 Deployment Project directly.

                    1. On your development machine, after compiling and testing your add-in (should be auto-registered while debugging and testing), open regedit.exe.  Browse to HKLM\Software\SolidWorks\AddIns key.  Search the sub keys for your add-in's registry key.  It will contain values for (Default), Description and Title.
                    2. Export your add-in's registry key (the folder with the GUID in {##}.
                    3. From the Solution Explorer in VS 2010, select your Deployment project and select the Registry Editor view from the quick access toolbar at the top of the Solution Explorer.
                    4. From the Registry window, right-click in the whitespace and select Import....  Browse to your exported registry and import.
                    5. Optional: In the same registry window, under HKCU\Software\SolidWorks\AddInsStartup, create another key using the same GUID as the imported GUID key name.  Create a new string value named (Default) and set its value to 1.  Your add-in will be enabled by default.
                    6. Check to make sure your add-in dll has automatically added it's HKEY_CLASSES_ROOT\CLSID entry in the deployment project.  If it hasn't, export HKCR\CLSID\{##### your GUID ####} from your development registry and import it to the deployment project.
                    7. Make sure your "Primary output from projectname" Register setting is vsdrpCOM and your add-in dll is registered for COM interop in its assembly information (Make assembly COM-visible).

                     

                         Hope that helps!

                     

                    Mike

                    • Re: Add-in installer with Visual Studio 2010
                      Christian Chu

                      This topic has been discussed here

                      • Re: Add-in installer with Visual Studio 2010
                        William Cruz

                        I take a different more straight forward approach when distributing my add-ins. I found that it's much easier and way faster to create a self-extracting executable using WinRar and have it run a *.bat file (install.bat in my case) as part of the extraction process. You can add a few options to the executable such as install folder, run as admin and so on, you can then save all these setting to a profile for re-use. Besides everything in the bin\release folder, I include the RegAsm.exe and obviously the install.bat file that does all the registration for me. The install.bat unRegisters the old DLL and registers the new one. Been doing it for many years now and has not failed. Let me know if you need more info.

                          • Re: Add-in installer with Visual Studio 2010
                            Christian Chu

                            it'd be much simple your way, I like the approach

                            Do you mind to share steps with us?

                              • Re: Add-in installer with Visual Studio 2010
                                William Cruz

                                Okay, the first step is to rename your *.dll (the one in the bin\release folder) to *.ren before packing – This is done so that it works both as an updater and installer. The *.bat file is executed AFTER the files have already been extracted to the destination folder. The *.bat file will then un-register the old, delete the old, rename the new and finally register the new file. See the attached file for a sample *.bat that I use as a template.

                                WinRar (v5.4):

                                1. Select all files, right-click and add to archive.
                                2. Archive format set to RAR.
                                3. Compression method set to best.
                                4. Archiving options set to “Create SFX archive” & “Create solid archive”.
                                5. Click the advance tab and select the SFX options:
                                  1. General:
                                    1. I have mine set to a folder under program files.
                                  2. Setup:
                                    1. In “run after extraction” put the full name of the install.bat file including extension.
                                  3. Advance:
                                    1. Check “Request administrative access.” (If needed)
                                  4. Update:
                                    1. “Extract and replace files”
                                    2. “Overwrite all files”
                                  5. Text and icon – License
                                    1. Under these two tabs you can put additional information for the user to see before installing.
                                6. I don’t fiddle around with the other settings but it doesn’t mean you don’t have to. I just stick with what works.

                                Important, after you have done all this setup for your install, click on the “Profiles..” button in the main page and save these setting to a profile, and I would normally name it the same name as the Add-In to make it easy to identify.

                            • Re: Add-in installer with Visual Studio 2010
                              Jan Jurjen Zwaard

                              Have you ever considered AddItIn? It's an SWX addin that allows you to build your own addin. You can embed your own collection of macros as a professional addin in SWX. You can easily add/remove macros and the addin will automatically be updated (no reinstallation required).

                               

                              It works with SWX macros, but also .NET DLL's including usercontrols.

                               

                              You can embed macros as buttons, taskpane tabs, context menu's, file open extensions and save extensions. You can even fire macros on certain SWX events (e.g. on startup to reset settings).

                               

                              I use it a lot to easily test the macros I'm making in the embedded (faster) environment.

                               

                              AddItIn - Studio Zwaard

                              • Re: Add-in installer with Visual Studio 2010
                                Keith Rice

                                The link you provided is referring to VS 2008 and 2010. I never used these, but I have a hard time believing that those instructions provided were sufficient for creating an EXE or MSI for distribution. I see no mention of specifying that the installer register your DLL(s) with COM or what registry keys to create in HKLM and HKCU.

                                 

                                I use Visual Studio 2015 with the Installer Projects extension, which, like VS 2015 Community Edition, is free from Microsoft. FYI, I sell a step-by-step guide on how to use this to create an MSI for your addin here.

                                 

                                If you decide all of this is too complex, note that the simplest way to distribute an addin is using BAT files. Instructions here. But this is arguably less professional than creating an installer EXE or MSI.

                                 

                                Keith

                                SolidWorks API Training and Services

                                • Re: Add-in installer with Visual Studio 2010
                                  Nilesh Patel

                                  Hi Jose,

                                   

                                  I found the following video by SolidWorks World very useful : SolidWorks World 2010 - Creating SolidWorks Add ins - YouTube

                                  Hope it helps.

                                   

                                  Regards,