Outlook Web Add-in清单报错:1.1命名空间元素含无效子元素
无上下文激活Outlook Web Add-in的清单错误解决方案
需求背景
开发无需启用阅读窗格或选中邮件即可激活的Outlook Web Add-in,基于Visual Studio提供的「Outlook Web Add-in」MessageRead模板,目标是让插件按钮随时显示并支持新建邮件操作。
问题描述
参照官方指南修改清单后,运行时弹出错误:
已尝试切换VersionOverrides版本(1.0与1.1互改)、同时包含两个版本覆盖等方案,均未解决问题。
修改后的清单代码
<?xml version="1.0" encoding="UTF-8"?> <!--Created:ce44715c-8c4e-446b-879c-ea9ebe0f09c8--> <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:mailappor="http://schemas.microsoft.com/office/mailappversionoverrides/1.0" xsi:type="MailApp"> <!-- Begin Basic Settings: Add-in metadata, used for all versions of Office unless override provided. --> <!-- IMPORTANT! Id must be unique for your add-in, if you reuse this manifest ensure that you change this id to a new GUID. --> <Id>308e295d-4e63-42c7-a6ef-eb93731d8e3f</Id> <!--Version. Updates from the store only get triggered if there is a version change. --> <Version>1.0.0.0</Version> <ProviderName>[Provider name]</ProviderName> <DefaultLocale>en-US</DefaultLocale> <!-- The display name of your add-in. Used on the store and various places of the Office UI such as the add-ins dialog. --> <DisplayName DefaultValue="OutlookWebAddIn_Transmittal" /> <Description DefaultValue="OutlookWebAddIn_Transmittal"/> <IconUrl DefaultValue="~remoteAppUrl/Images/icon64.png"/> <SupportUrl DefaultValue="http://www.contoso.com" /> <!-- Domains that will be allowed when navigating. For example, if you use ShowTaskpane and then have an href link, navigation will only be allowed if the domain is on this list. --> <AppDomains> <AppDomain>AppDomain1</AppDomain> <AppDomain>AppDomain2</AppDomain> <AppDomain>AppDomain3</AppDomain> </AppDomains> <!--End Basic Settings. --> <Hosts> <Host Name="Mailbox" /> </Hosts> <Requirements> <Sets> <Set Name="Mailbox" MinVersion="1.1" /> </Sets> </Requirements> <FormSettings> <Form xsi:type="ItemRead"> <DesktopSettings> <SourceLocation DefaultValue="~remoteAppUrl/MessageRead.html"/> <RequestedHeight>250</RequestedHeight> </DesktopSettings> </Form> </FormSettings> <Permissions>ReadWriteItem</Permissions> <Rule xsi:type="RuleCollection" Mode="Or"> <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" /> </Rule> <DisableEntityHighlighting>false</DisableEntityHighlighting> <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides" xsi:type="VersionOverridesV1_0"> <VersionOverrides xmlns="http://schemas.microsoft.com/office/mailappversionoverrides/1.1" xsi:type="VersionOverridesV1_1"> <Requirements> <bt:Sets DefaultMinVersion="1.13"> <bt:Set Name="Mailbox"/> </bt:Sets> </Requirements> <Hosts> <Host xsi:type="MailHost"> <DesktopFormFactor> <!-- Message Read mode--> <ExtensionPoint xsi:type="MessageReadCommandSurface"> <OfficeTab id="TabDefault"> <Group id="msgReadGroup"> <Label resid="GroupLabel"/> <Control xsi:type="Button" id="msgReadOpenPaneButton"> <Label resid="TaskpaneButton.Label"/> <Supertip> <Title resid="TaskpaneButton.Label"/> <Description resid="TaskpaneButton.Tooltip"/> </Supertip> <Icon> <bt:Image size="16" resid="icon16" /> <bt:Image size="32" resid="icon32" /> <bt:Image size="80" resid="icon80" /> </Icon> <Action xsi:type="ShowTaskpane"> <SourceLocation resid="messageReadTaskPaneUrl"/> <!-- Enables your add-in to activate without the Reading Pane enabled or a message selected. --> <SupportsNoItemContext>true</SupportsNoItemContext> </Action> </Control> </Group> </OfficeTab> </ExtensionPoint> </DesktopFormFactor> </Host> </Hosts> <Resources> <bt:Images> <bt:Image id="icon16" DefaultValue="~remoteAppUrl/Images/icon16.png"/> <bt:Image id="icon32" DefaultValue="~remoteAppUrl/Images/icon32.png"/> <bt:Image id="icon80" DefaultValue="~remoteAppUrl/Images/icon80.png"/> </bt:Images> <bt:Urls> <bt:Url id="functionFile" DefaultValue="~remoteAppUrl/Functions/FunctionFile.html"/> <bt:Url id="messageReadTaskPaneUrl" DefaultValue="~remoteAppUrl/MessageRead.html"/> </bt:Urls> <bt:ShortStrings> <bt:String id="GroupLabel" DefaultValue="Test walkthrough"/> <bt:String id="TaskpaneButton.Label" DefaultValue="Show Taskpane"/> </bt:ShortStrings> <bt:LongStrings> <bt:String id="TaskpaneButton.Tooltip" DefaultValue="Opens a task pane."/> </bt:LongStrings> </Resources> </VersionOverrides> </VersionOverrides> </OfficeApp>
解决方案
1. 调整根节点规则,允许无上下文加载
根节点的<Rule>限制了插件仅在选中已读邮件时加载,与无上下文激活需求冲突。将其替换为允许插件在任意邮箱上下文加载的规则:
<Rule xsi:type="RuleCollection" Mode="Or"> <Rule xsi:type="ItemIs" ItemType="Message" FormType="Read" /> <Rule xsi:type="True" /> </Rule>
<Rule xsi:type="True" />表示插件始终满足加载条件,确保按钮在无选中邮件时也能显示。
2. 提升权限等级
将<Permissions>从ReadWriteItem改为ReadWriteMailbox,无上下文激活需要更高的权限范围:
<Permissions>ReadWriteMailbox</Permissions>
3. 验证版本兼容性
确认测试环境的Outlook客户端/网页版支持Mailbox API 1.13或更高版本(SupportsNoItemContext从该版本开始支持)。若环境版本不足,可降低VersionOverrides中的DefaultMinVersion,但需注意部分功能可能受限。
4. 优化任务窗页逻辑
在MessageRead.html对应的脚本中,添加无上下文时的处理逻辑,避免因无选中邮件导致的初始化错误:
Office.onReady(async () => { // 检查是否有选中项目 if (Office.context.mailbox.item) { // 原有处理逻辑 } else { // 无上下文时直接显示新建邮件界面 await Office.context.mailbox.displayNewMessageForm({ subject: "新建邮件", body: "这是通过插件创建的邮件" }); } });
替代方法:使用FunctionCommand直接新建邮件
若任务窗格方案仍有问题,可改用命令按钮直接触发新建邮件操作,无需打开任务窗格:
- 在
VersionOverrides的ExtensionPoint中添加一个Button,类型改为ExecuteFunction:
<Control xsi:type="Button" id="createNewMailButton"> <Label resid="CreateMailButton.Label"/> <Supertip> <Title resid="CreateMailButton.Label"/> <Description resid="CreateMailButton.Tooltip"/> </Supertip> <Icon> <bt:Image size="16" resid="icon16" /> <bt:Image size="32" resid="icon32" /> <bt:Image size="80" resid="icon80" /> </Icon> <Action xsi:type="ExecuteFunction"> <FunctionName>createNewMessage</FunctionName> <SupportsNoItemContext>true</SupportsNoItemContext> </Action> </Control>
- 在资源部分添加对应的字符串:
<bt:ShortStrings> <bt:String id="CreateMailButton.Label" DefaultValue="新建邮件"/> </bt:ShortStrings> <bt:LongStrings> <bt:String id="CreateMailButton.Tooltip" DefaultValue="直接创建新邮件"/> </bt:LongStrings>
- 在
FunctionFile.html中实现createNewMessage函数:
function createNewMessage() { Office.context.mailbox.displayNewMessageForm({ subject: "插件创建的新邮件", body: "邮件内容" }); }
内容的提问来源于stack exchange,提问作者Trent Hardy
相关产品推荐
相关产品推荐

