Skip to content

Commit a40f558

Browse files
[All Hosts] (publishing) update to publish with Windows app (#5215)
* [All Hosts] (publishing) update to publish with Windows app * mainly typos * clarify note * correct new registry path * Update publish-office-add-ins-to-appsource.md * Apply suggestions from code review Co-authored-by: Alison McKay <[email protected]> --------- Co-authored-by: Alison McKay <[email protected]>
1 parent c44f8cb commit a40f558

File tree

1 file changed

+75
-21
lines changed

1 file changed

+75
-21
lines changed

docs/publish/publish-office-add-ins-to-appsource.md

Lines changed: 75 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
title: Publish your Office Add-in to Microsoft AppSource
33
description: Learn how to publish your Office Add-in to Microsoft AppSource and install the add-in with a Windows app or COM/VSTO add-in.
44
ms.topic: concept-article
5-
ms.date: 02/24/2025
5+
ms.date: 06/06/2025
66
CustomerIntent: As a developer, I want to publish my Office Add-in to Microsoft AppSource so that customers can deploy and use my new add-in.
77
---
88

@@ -128,6 +128,15 @@ We recommend that your installation check whether the user has the Office applic
128128

129129
The exact code needed depends on the installation framework and the programming language that you are using. The following is an example of how to check using C#.
130130

131+
> [!NOTE]
132+
> The installation can be designed to install the add-in for all users of the computer, if an administrator of the computer is running the installation program. To implement that design, update the code to do the following.
133+
>
134+
> - Check if the user is an administrator of the computer.
135+
> - If the user is an administrator, the code should do one of the following.
136+
>
137+
> - If you want to force the add-in to be installed for all users, the code should set the `supportLocalComputer` variable to `true`.
138+
> - If you want to give the administrator a choice between installing the add-in only for themself or for all users on the computer, the code should present a dialog to the administrator, return the administrator's choice, and set the `supportLocalComputer` variable accordingly.
139+
131140
```csharp
132141
using Microsoft.Win32;
133142
using System;
@@ -146,10 +155,15 @@ namespace SampleProject
146155
string basePath = @"Software\Microsoft\Office";
147156
RegistryKey baseKey = Registry.CurrentUser.OpenSubKey(basePath);
148157
string wxpName = "Word"; // Can be one of "Word", "Powerpoint", or "Excel".
158+
bool supportLocalComputer = false; // True means LOCAL_MACHINE support, false means CURRENT_USER support.
149159
150160

151161
const string buildNumberStr = "BuildNumber";
152162
const int smallBuildNumber = 18227; // This is the minimum build that supports installation of a web add-in in the installation of a Windows app.
163+
if (supportLocalComputer)
164+
{
165+
smallBuildNumber = 18730; // This is the minimum build that supports installation of a web add-in, for all users of the computer, in the installation of a Windows app.
166+
}
153167
const int supportedBuildMajorNumber = 16; // 16 is the lowest major build of Office applications that supports web add-ins.
154168
155169
if (baseKey != null)
@@ -295,11 +309,16 @@ namespace SampleProject
295309

296310
##### Create a registry key for the add-in (required)
297311

298-
Include in the installation program a function to add an entry like the following example to the Windows Registry.
312+
Include in the installation program a function to add *one* of the following keys and values to the Windows Registry, depending on whether the add-in is being installed for all users of the computer or only for the user that is running the installation program.
299313

300314
```
315+
// Only the current user.
301316
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
302317
"AssetIds"="{{assetId}}"
318+
319+
// All users of the computer.
320+
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
321+
"AssetIds"="{{assetId}}"
303322
```
304323

305324
Replace the placeholders as follows:
@@ -315,37 +334,53 @@ Replace the placeholders as follows:
315334
The following is an example.
316335

317336
```
337+
// Only the current user.
318338
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\Word\ContosoAdd-in]
319339
"AssetIds"="WA999999999"
340+
341+
// All users of the computer.
342+
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\Word\ContosoAdd-in]
343+
"AssetIds"="WA999999999"
320344
```
321345

322-
The exact code will depend on your installation framework and programming language. The following is an example in C#.
346+
The exact code depends on your installation framework and programming language. The following is an example in C#.
323347

324-
```csharp
348+
> [!NOTE]
349+
> To install the add-in for all users, change this code so that `WriteRegisterKeys` takes a `bool` parameter. The method should set the `supportLocalMachine` variable to the value that is passed: `true` to install for all users, `false` to install for only the current user.
350+
351+
```csharp
325352
using Microsoft.Win32;
326353
using System;
327354

328355
namespace SampleProject
329356
{
330-
internal class WriteRegisterKeysSample
331-
{
357+
internal class WriteRegisterKeysSample
358+
{
332359
/// <summary>
333360
/// This function writes information to the registry that will tell Office applications to install the web add-in.
334361
/// </summary>
362+
335363
private void WriteRegisterKeys()
336364
{
337-
RegistryKey hklm = Registry.CurrentUser;
338-
string basePath = @"Software\Microsoft\Office";
339-
RegistryKey baseKey = Registry.CurrentUser.OpenSubKey(basePath);
340-
string wxpName = "Word"; // Can be one of "Word", "Powerpoint", or "Excel".
341-
string assetID = "WA999999999"; // Use the AppSource asset ID of your web add-in.
342-
string appName = "ContosoAddin"; // Pass your own web add-in name.
343-
const int supportedBuildMajorNumber = 16; // Major Office build numbers before 16 do not support web add-ins.
344-
const string assetIdStr = "AssetIDs"; // A registry key to indicate that there is a web add-in to install along with the main app.
365+
bool supportLocalMachine = false; // false = CurrentUser, true = LocalMachine
366+
RegistryKey targetRootKey = supportLocalMachine ? Registry.LocalMachine : Registry.CurrentUser;
345367

346-
if (baseKey != null)
368+
string basePath = @"Software\Microsoft\Office";
369+
using (RegistryKey baseKey = targetRootKey.OpenSubKey(basePath))
347370
{
348-
Version maxVersion = new Version(supportedBuildMajorNumber, 0); // Initial value for the max supported build version.
371+
if (baseKey == null)
372+
{
373+
Console.WriteLine("Base registry path not found.");
374+
return;
375+
}
376+
377+
string wxpName = "Word"; // Can be "Word", "Powerpoint", or "Excel".
378+
string assetID = "WA999999999"; // AppSource asset ID of your web add-in.
379+
string appName = "ContosoAddin"; // Your web add-in name.
380+
const int supportedBuildMajorNumber = 16;
381+
const string assetIdStr = "AssetIDs";
382+
383+
Version maxVersion = new Version(supportedBuildMajorNumber, 0);
349384
foreach (string subKeyName in baseKey.GetSubKeyNames())
350385
{
351386
if (Version.TryParse(subKeyName, out Version version))
@@ -358,15 +393,24 @@ namespace SampleProject
358393
}
359394

360395
string maxVersionString = maxVersion.ToString();
396+
string subKeyPath = supportLocalMachine
397+
? $@"Software\Microsoft\Office\{maxVersionString}\AutoInstallAddins\{wxpName}\{appName}"
398+
: $@"Software\Microsoft\Office\{maxVersionString}\Wef\AutoInstallAddins\{wxpName}\{appName}";
361399

362-
// Create the path under AutoInstalledAddins to write the AssetIDs value.
363-
RegistryKey AddInNameKey = hklm.CreateSubKey(String.Format(@"Software\Microsoft\Office\{0}\Wef\AutoInstallAddins\{1}\{2}", maxVersionString, wxpName, appName));
364-
if (AddInNameKey != null)
400+
using (RegistryKey addInKey = targetRootKey.CreateSubKey(subKeyPath))
365401
{
366-
AddInNameKey.SetValue(assetIdStr, assetID);
402+
if (addInKey != null)
403+
{
404+
addInKey.SetValue(assetIdStr, assetID);
405+
}
406+
else
407+
{
408+
Console.WriteLine("Failed to create or open the registry subkey.");
409+
}
367410
}
368411
}
369412
}
413+
370414
}
371415
}
372416
```
@@ -375,18 +419,28 @@ namespace SampleProject
375419

376420
Skip this section if you aren't a member of the certification program, but *it is required if you are*.
377421

378-
Include in the installation program code to add an entry like the following example to the Windows Registry.
422+
Include in the installation program code to add *one* of the following keys and values to the Windows Registry, depending on whether the add-in is being installed for all users of the computer or only for the user that is running the installation program.
379423

380424
```
425+
// Only the current user.
381426
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
382427
"HasPrivacyLink"="1"
428+
429+
// All users of the computer.
430+
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\{{OfficeApplication}}\{{add-inName}}]
431+
"HasPrivacyLink"="1"
383432
```
384433

385434
Replace the `{{OfficeApplication}}` and `{{add-inName}}` placeholders exactly as in the preceding section. The following is an example.
386435

387436
```
437+
// Only the current user.
388438
[HKEY_CURRENT_USER\Software\Microsoft\Office\16.0\Wef\AutoInstallAddins\Word\ContosoAdd-in]
389439
"HasPrivacyLink"="1"
440+
441+
// All users of the computer.
442+
[HKEY_LOCAL_MACHINE\Software\Microsoft\Office\16.0\AutoInstallAddins\Word\ContosoAdd-in]
443+
"HasPrivacyLink"="1"
390444
```
391445

392446
To implement this, just make two small changes in the code sample in the previous section.

0 commit comments

Comments
 (0)