Shared Runtime

When running Excel on Windows or Mac, your add-in will run code for ribbon buttons, custom functions, and the task pane in separate JavaScript runtime environments.
This creates limitations such as not being able to easily share global data, and not being able to access all CORS functionality from a custom function.
link - docs.microsoft.com/en-us/office/dev/add-ins/excel/configure-your-add-in-to-use-a-shared-runtime
link - docs.microsoft.com/en-us/office/dev/add-ins/excel/call-excel-apis-from-custom-function
link - github.com/OfficeDev/PnP-OfficeAddins/tree/master/Samples/excel-shared-runtime-scenario


not currently sharing with dialogs ??


Shared Runtime 1.1

Only available in Excel
Only available in PowerPoint (currently in Preview)
Not available in Word


Benefits of a Shared Runtime

Your add-in will have a shared DOM that the ribbon, task pane, and custom functions can all access.
Your custom functions will have full CORS (Cross Origin Resource Sharing) support.
Your custom functions can call Office.js APIs to read spreadsheet document data.
Your add-in can run code as soon as the document is opened.
Your add-in can continue running code after the task pane is closed.
You can't use Visual Studio Code to debug custom functions in Excel on Windows at the moment.


Runtime Element

In the VersionOverrides section add a <Runtimes> element.
Change the Runtime resid to be "SharedRuntime.Url" and the lifetime to be "long".

<VersionOverrides> 
  <Hosts>
    <Host xsi:type="Workbook">
    <Runtimes>
      <Runtime resid="SharedRuntime.Url" lifetime="long" />
    </Runtimes>
    <AllFormFactors>

<long> - Starting your add-in when the document opens. Continuing to run code after the task pane has closed. Using CORS and DOM from custom functions.
<short> - This is the default. The runtime will only start when a ribbon button is pressed or a task pane is opened. The runtime might stop after a ribbon handler or after a task pane is closed.


Consistent URL


In the VersionOverrides section find the <AllFormFactors> element.
Change SourceLocation resid for the <Page> to be "SharedRuntime.Url".

<ExtensionPoint xsi:type="CustomFunctions"> 
  <Page>
    <SourceLocation resid="SharedRuntime.Url"/>
  </Page>

In the VersionOverrides section find the <DesktopFormFactor> element.
Change the FunctionFile resid to be "SharedRuntime.Url".

<DesktopFormFactor> 
  <FunctionFile resid="SharedRuntime.Url" />

In the VersionOverrides section find the <Action> element.
Change the SourceLocation resid to be "SharedRuntime.Url".

<Action xsi:type="ShowTaskpane"> 
  <TaskpaneId>MyTaskpaneID</TaskpaneId>
    <SourceLocation resid="URL_Taskpane1"/>
</Action>

In the VersionOverrides section find the <Urls> element.
Add a new item for SharedRuntime.Url.

<bt:Urls> 
  <bt:Url id="SharedRuntime.Url" DefaultValue="https://localhost:3000/dist/taskpane.html" />

Multiple Task Panes

Don't design your add-in to use multiple task panes if you are planning to use a shared runtime.
A shared runtime only supports the use of one task pane.
Note that any task pane without a <TaskpaneID> is considered a different task pane.


Simple Shared Runtime

<?xml version="1.0" encoding="UTF-8"?> 
<OfficeApp
  xmlns="http://schemas.microsoft.com/office/appforoffice/1.1"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xmlns:bt="http://schemas.microsoft.com/office/officeappbasictypes/1.0"
  xmlns:ov="http://schemas.microsoft.com/office/taskpaneappversionoverrides"
  xsi:type="TaskPaneApp">

  <Id>120ad42d-6839-4f7b-8d6e-f14bd60e524f</Id>
  <Version>1.0.0.0</Version>
  <ProviderName>Better Solutions Limited</ProviderName>
  <DefaultLocale>en-US</DefaultLocale>
  <DisplayName DefaultValue="ExcelJSAddIn1" />
  <Description DefaultValue="ExcelJSAddIn1"/>
  <SupportUrl DefaultValue="https://bettersolutions.com"/>
  <AppDomains>
    <AppDomain>AppDomain1</AppDomain>
  </AppDomains>
  <Requirements>
    <Sets DefaultMinVersion="1.1">
      <Set Name="SharedRuntime" MinVersion="1.1" />
    </Sets>
  </Requirements>
  <DefaultSettings>
    <SourceLocation DefaultValue="http://localhost:8080/index.html" />
  </DefaultSettings>
  <Permissions>ReadWriteDocument</Permissions>
<VersionOverrides xmlns="http://schemas.microsoft.com/office/taskpaneappversionoverrides" xsi:type="VersionOverridesV1_0">
  <Hosts>
    <Host xsi:type = "Workbook">
      <Runtimes>
         <Runtime resid="SharedRuntime.Url" lifetime="long" />
      </Runtimes>
      <DesktopFormFactor>
         <FunctionFile resid="SharedRuntime.Url"/>
      </DesktopFormFactor>
    </Host>
  </Hosts>
  <Resources>
    <bt:Urls>
      <bt:Url id="SharedRuntime.Url" DefaultValue="http://localhost:8080/index.html"/>
    </bt:Urls>
  </Resources>
</VersionOverrides>
</OfficeApp>


© 2021 Better Solutions Limited. All Rights Reserved. © 2021 Better Solutions Limited TopPrevNext