Update SolidWorks add-in on start-up

Hi,
I developed an add-in for internal use in my company; I also created an installer with WiX Toolset.

Whenever I make an update to the add-in, I make the installer available on a shared folder for the ten users in my department. The installer is very basic, it requires no configuration from the user, just to click OK a couple of times. Nevertheless most of my colleagues do not install the new version and I find myself to update every workstation manually.

I saw here that is possible to check for update.

I’m looking for a tool to do that. Requirements:

  • It should be free: the user-base is small and it’s for internal use only, so I will not be able to justify a professional solution
  • Ideally it should be simple to implement: I’m not a programmer and my knowledge of C# and the .NET framework is still very basic

Thanks in advance!

1 Like

In the example that you linked, I hosted an MSI installer in a common location in PDM. I am using the following function to query the attribute

  • "ProductVersion" - 1.0.0.0
private string getMSIAttribute(string msiFile, string property)
{
    string retVal = string.Empty;

    using (Microsoft.Deployment.WindowsInstaller.Database database = new Microsoft.Deployment.WindowsInstaller.Database(msiFile, Microsoft.Deployment.WindowsInstaller.DatabaseOpenMode.ReadOnly))
    {
        retVal = database.ExecutePropertyQuery(property);
    }

    return retVal;
}

Once I have that, I can get the current version of the add-in with:

var currentVersion = Assembly.GetExecutingAssembly().GetName().Version.ToString()

You can then wrap the version numbers using the built-in Version class

var myCurrentVersion = new Version(currentVersion)
var versionOnServer = new Version(getMSIAttribute(installerPath, "ProductVersion"))

Once you have those, you can CompareTo to see if which is newer with

installedVersion.CompareTo(serverVersion) < 0 // returns 1 if first comparison is newer, -1 if first comparison is older, and 0 if they are the same

If they match, I have my program ask the user if they want to upgrade and if they click yes then I call

Process.Start(installerPath)
1 Like

Hi @BigCrazyAl!

Thanks for the reply. I will give it a try.

A couple of question:

  • If I understand it correctly you check the version during the add-in connection to SolidWorks. If the user decide to update how do you quit SolidWorks? Is Application.Close(); sufficient? (I am using xCAD.net in this case).
  • In the linked post I saw @AmenJlili to reference both to a new thread and to get the handle of the SolidWorks splash screen to make sure the message box is shown on top. Can I ask how do end up implementing that?

Thanks!

I am actually not closing the program myself only because I check the version after the add-in is loaded in SW. When the installer is triggered, it comes up with a prompt that says Soldiworks needs to be closed in order to continue.

I also didn’t need to do anything with a reference to the splash screen since my add-in checks only when it becomes visible in the taskpane. Now, I know I didn’t do this the best way but it works for my application. If I were to go back, I may create an updater as a separate program and allow it to do everything outside of the add-in.

Please no advertisement of commercial products.