Unload an addin within the addin itself

Add-in Express™ Support Service
That's what is more important than anything else

Unload an addin within the addin itself
 
nwein




Posts: 577
Joined: 2011-03-28
I'm trying to run an update mechanism without closing the host (Outlook 2010).
I can achieve it manually if I unload the COM addin through the COM Add-ins dialog (in the developer tab), run my msi and then re-enable the add-in.
As a first go I thought I'd have a macro that disables the add-in runs the msi and re-enable the (now updated) add-in.
This works fine.
However if I call that macro from my code, everything crashes (the add-in crashing is fine, but the host crashes as well). I can somehow understand, as the calling code gets disposed, but still, I wonder if it's possible.
An alternative approach was to create another add-in that all of its purpose is to do update the other add-in. However I'm encountering some annoying "process is being used" messages when trying to run the first add-in's installer (while it's unloaded) - this doesn't happen if the macro is running the msi.
Any help on this?
Posted 01 Oct, 2015 12:07:14 Top
nwein




Posts: 577
Joined: 2011-03-28
Never mind the second solution, it was me loading the dll of the first add-in (therefore preventing a proper update as the first add-in dll is in use by the second add-in). So the second solution seems to work, but I don't really like the fact that I have 2 add-ins where one's whole purpose is to update the other.
If I could get by with the macro that would be much cleaner.
Posted 01 Oct, 2015 12:37:54 Top
Michael Thrift




Posts: 41
Joined: 2015-06-09
I am trying to accomplish the same thing with My Excel Add-in. We have recently switched from a VSTO Add-In to Add-In Express. I'm not sure about how this is accomplished, but with VSTO, the VSTOLoader is responsible for creating the AppDomain and Loading the Add-In into Excel. It manages to check and install updates before it loads the Add-In, and therefore the instance of Excel that was opened does not need to be closed or restarted.

With ADX, the CLickOnce is not the Add-In but the installer itself?? I Think. Anyway, I'm able to manually check for an required update by reading the deployment manifest in code. If it is done in the AddInInitialize or BeforeRibbonCreate, perhaps the dll can be replaced before it is loaded into the APP Domain.

I would like to know why a VSTO Addin can be updated without requiring the closing or restarting on the HOST Application. TO be clear, if Excel is open, and an update is available. I understand that there is now way to get the update. But there should be a way for the opening of a new instance of EXCEL to recognize that an update is available, and update the Add-IN before it gets loaded into the AppDomain.
Posted 01 Oct, 2015 21:16:20 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Hello Nir and Michael,

You can replace the add-in without restarting the host application if you have some program which is external to the add-in. You use that program to turn the add-in off before uninstalling the current version. Then, after installing the add-in, you may need to turn it on. But this procedure doesn't look user-friendly. We recommend restarting the host application.

Michael Thrift writes:
With ADX, the CLickOnce is not the Add-In but the installer itself??


ClickOnce supports VSTO add-ins; it doesn't support COM add-ins. This makes the solution that Add-in Express provides limited. You cannot update an Add-in Express based add-in before it loads. Please find more details in section Add-in Express ClickOnce Solution in the manual, see the PDF file in the folder {Add-in Express}\Docs on your development PC.

Setting ShadowCopy=true in adxloader.dll.manifest won't help you update the add-in before it gets loaded.


Andrei Smolin
Add-in Express Team Leader
Posted 02 Oct, 2015 09:30:52 Top
Michael Thrift




Posts: 41
Joined: 2015-06-09
Andre,

Could a custom SHIM be responsible for checking if there is an updated required to the Add-In Assemblies, make the update, then go through the process of creating the AppDomain and loading the assemblies?

Can you speak in a little more detail as to why a VSTO Add-In is able to update itself during the startup of EXCEL without having to close the HOST Application.

Also, I assume ALL instances of EXCEL would need to be closed in the Add-In Express version. If I checked for an update in the Add-In Initialize Method, I would need to close all instances of EXCEL, not just the instance that found the update.

Thanks!
Posted 02 Oct, 2015 09:46:01 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
Michael,

The Add-in Express loader is unmanaged. ClickOnce belongs to the managed world.

Michael Thrift writes:
Can you speak in a little more detail as to why a VSTO Add-In is able to update itself during the startup of EXCEL without having to close the HOST Application


ClickOnce supports VSTO add-ins; and Office supports them. I think that the startup procedures of an Office application includes contacting VSTO Loader which invokes ClickOnce (if required). If this is so, then the host application is waiting while ClickOnce updates your add-in.

Michael Thrift writes:
Also, I assume ALL instances of EXCEL would need to be closed in the Add-In Express version.


Exactly. Otherwise, you won't be able to update the add-in's files as they will be locked.


Andrei Smolin
Add-in Express Team Leader
Posted 02 Oct, 2015 09:58:10 Top
nwein




Posts: 577
Joined: 2011-03-28
I'm not even trying to get this solution to work with my Excel add-in due to the multiple instances problem, that's why I narrowed it down to Outlook only.
Going back to my original question, instead of having a second application that does the unload-update-reload, why can't I achieve this programmatically from my add-in calling a pre-defined macro (that does just that)?
Posted 02 Oct, 2015 10:08:24 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
nwein writes:
why can't I achieve this programmatically from my add-in calling a pre-defined macro


The Outlook object model doesn't let you call a VBA macro. They allowed to run a public macro defined in ThisSession module via Outlook.Appliaction.MyMacro; as far as I know this isn't supported since Outlook 2007. The description is at https://support.microsoft.com/en-us/kb/221827.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Oct, 2015 06:40:59 Top
nwein




Posts: 577
Joined: 2011-03-28
You're right about that, but calling a command bar/ribbon button associated with a macro is possible, and as far as I remember, from my tests, calling a macro that doesn't involve in killing the add-in works just fine.
Posted 05 Oct, 2015 09:45:27 Top
Andrei Smolin


Add-in Express team


Posts: 18829
Joined: 2006-05-11
I would try to start a timer in that macro and unload the add-in when the timer wakes up.


Andrei Smolin
Add-in Express Team Leader
Posted 05 Oct, 2015 09:54:48 Top