Self updating AddIn

Self updating AddIn

Jef_E
Collaborator Collaborator
3,002 Views
24 Replies
Message 1 of 25

Self updating AddIn

Jef_E
Collaborator
Collaborator

Hi!

 

I made an AddIn that is actively used at my company. And by actively I mean by the users and the developer (me), so there are frequent updates for the AddIn holding new features and bug fixes.

 

Currently when a new version goes live, a Email is sent to ALL of the end-users that they need to run the installer to get the latest .dll file on their computer.

 

To avoid that someone forgets or ignores the email I would like to compare the AddIn .dll files the local one stored under

 

C:\Program Files\Autodesk\Inventor 2014\Bin

And the one on the network drive ( or maybe in the future, on the FTP server ). I did some research and found a way to do this check.

 

Dim myFileVersionInfo As FileVersionInfo
myFileVersionInfo = FileVersionInfo.GetVersionInfo("C:\Program Files\Autodesk\Inventor 2014\Bin\xxxx.dll")

Dim serverFileVersionInfo As FileVersionInfo
serverFileVersionInfo = FileVersionInfo.GetVersionInfo("T:\Inventor\Tools\xxxxx\xxxxx.dll")

Debug.Print(String.Compare(myFileVersionInfo.ProductVersion, serverFileVersionInfo.ProductVersion))

When this result = -1 the local file is out of date and the .dll file should be replaced. Problem is.. When Inventor is running the .dll file cannot be replaced. How should I handle this?

 

My check is currently situated in the activate sub

        Public Sub Activate(ByVal addInSiteObject As Inventor.ApplicationAddInSite, ByVal firstTime As Boolean) Implements Inventor.ApplicationAddInServer.Activate

            ' This method is called by Inventor when it loads the AddIn.
            ' The AddInSiteObject provides access to the Inventor Application object.
            ' The FirstTime flag indicates if the AddIn is loaded for the first time.

            ' Initialize AddIn members.
            m_inventorApplication = addInSiteObject.Application
            
            ' Check for the file
            FileVersionCheck()

        End Sub


Please kudo if this post was helpfull
Please accept as solution if your problem was solved

Inventor 2014 SP2
0 Likes
3,003 Views
24 Replies
Replies (24)
Message 21 of 25

nmunro
Collaborator
Collaborator

You should not try to modify GUID values manually. Use Visual Studio's GUID generator (Tools > Create GUID) to generate a new GUID with the Registry Format option. You can generate new GUIDs until you see one that you would like to use. 

 

Example: GUID #1 - with braces removed: 220FF765-7C34-4CCD-9388-38E850D854EB

Example: GUID #2 - with braces removed: 522E8C35-F54B-4C41-938A-C02BD45C7B50

 

GUID #1 is "lower" than GUID #2 (starts with '2' vs starts with '5') so in this example you would use that one for the management add-in and the second one for the updatable add-in.

 

Make sure you use the same GUID for the GuidAttribute for the AddInServer class, and as the <ClassId> and <ClientId> element values in the .addin file for that particular add-in. The .addin file requires the GUID to include the braces {} for both elements.

 

Example: <ClassId>{220FF765-7C34-4CCD-9388-38E850D854EB}</ClassId>

 

In addition, the .manifest file for the add-in also requires this GUID (with braces) in the classid attribute of the clrClass element.

 

Example:

 

<clrClass clsid="{220FF765-7C34-4CCD-9388-38E850D854EB}"

  ...

</clrClass>

        


https://c3mcad.com

0 Likes
Message 22 of 25

Slothian
Contributor
Contributor

@nmunro Thanks for the instructions, I redid the GUIDs for my addins but seems to have made no difference in the load order.

 

This is the load order I am after (with VS generated GUID numbers)

ABC_Common    {4686D98E-E90B-47B2-BEA9-C2BC80E4FC8F}
ABC                      {615F6E2A-15D8-44C9-8F2D-7A9DDEEB57FF}

but I am getting ABC displaying the messagebox in activate first, followed by the messagebox for ABC_Common

As I am ulitmately wanting an updater to manage these, I created a new project ABC_Updater and followed the same proceedure for lower GUID number and added a messagebox to check load order

ABC_Updater    {12AD759D-4443-435B-A715-3020041E7064}

 

Testing is giving me the following order of messageboxs

 

ABC

ABC_Updater

ABC_Common

Scratching my head as to why I am getting this load order, any ideas?

0 Likes
Message 23 of 25

nmunro
Collaborator
Collaborator

Can you post a zip of all three projects?

        


https://c3mcad.com

0 Likes
Message 24 of 25

nmunro
Collaborator
Collaborator

The attached IV_Addins.zip file has two very simple add-in projects (each just shows a message box on startup) that demonstrate this process. Inventor has changed quite a bit on how it manages add-ins over the years but this approach still works with a bit of planning.

 

It is important to have the GUID assignment in place before you have Inventor load it for the first time. This initial load will use the GUID to set it's load order compared to other add-ins. This has always been the case but Inventor seems to hang on to this relative order more strongly in later versions. This is likely why you were seeing your initial add-in still loading first even though it has a 'higher' GUID as its identifier.  What this really means that you can't change the GUID after loading it the first time in expectation of changing the load order. There is a method to reset loading of add-ins but Inventor still hangs on to the original loading order. I will do some more digging to see if this behavior can be circumvented. 

 

Note that when Inventor generates the GUID for the add-in's GuidAttribute, it converts all alpha characters to lower case. This should not be an issue if this is always converted to a GUID, but if Inventor is reading this as a string then it may cause issues if you use upper case characters in generated GUIDs.  The attached Guids.zip file contains a console application that will generate 30 lower case GUIDs and write them to a text file in your C:\Temp\ folder. Remember to remove the GUID from the file if you use it anywhere so that you don't accidently use it a second time.

 

--------------

The attached IV_Addins.zip file contains both Visual Studio projects for the two add-ins. They were created in VS 2019 but you can probably open them in VS 2015 or later.  Unzip the file to create an IV_Addins folder.

 

In the IV_Addins folder, open the \Created_01\InventorAddIn1.sln file to load the first add-in project. This project has a GUID that begins with "b". Build the project. It copies the output to the C:\ProgramData\Autodesk\Inventor Addins\TestAddIns\InventorAddIn1\ folder, including the required .addin file.

 

Start Inventor (should work with IV 2019 or later). You will likely see a message that the Add-In is blocked. Open the Inventor Add-In manager and uncheck Blocked. Check Load Automatically but don't check the Loaded/Unloaded check box.

 

Close Inventor and then restart it. The add-in should display a message with the GUID used for the GuidAttribute.

 

------------

 

In the IV_Addins folder, open the \Created_02\InventorAddIn_Second.sln file to load the second add-in project. This project has a GUID that begins with "0" (zero) which results a 'lower' GUID than the first project. Build the project. It copies the output to the C:\ProgramData\Autodesk\Inventor Addins\TestAddIns\InventorAddIn_Second\ folder, including the required .addin file.

 

Start Inventor. If the second add-in is blocked: Open the Add-In Manager. Uncheck Blocked. Check Load on Startup. Do not check Loaded/Unloaded.

 

Close Inventor and restart. You should see two messages. The first one will be from the second add-in since it has a lower GUID. 

 

Hope this helps.

 

        


https://c3mcad.com

Message 25 of 25

Slothian
Contributor
Contributor

Thanks @nmunro for the extra info. Strangest behaviour though, since your last post I was on holidays and when I returned, the load order is now working as expected. No changes made between then and now but definately a difference as to correct loading order!

0 Likes