首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >有没有办法强制ClickOnce安装将VSTO插件的LoadBehavoir设置为"0“

有没有办法强制ClickOnce安装将VSTO插件的LoadBehavoir设置为"0“
EN

Stack Overflow用户
提问于 2018-11-14 06:17:03
回答 2查看 109关注 0票数 1

我对作为VSTO解决方案开发的Excel Ribbon外接程序的加载行为有困难。外接程序用作具有多个选项卡的Excel VSTO功能区控件,默认情况下,每个选项卡的可见性设置为false,并通过工作簿的外接程序实例化使其可见。

出于我不清楚的原因,允许ClickOnce安装将LoadBehavior设置为16 (然后设置为9)是有问题的。初始值16将正确加载工作簿功能区选项卡,但关闭并重新打开同一工作簿后,功能区选项卡将不显示。

但是,如果使用相同的外接程序打开另一个工作簿,则这两个选项卡都会出现在每个工作簿中。

LoadBehavior "0“在任何情况下都可以正常工作,并且是发布问题的原因。

以下是外接程序实例化的VBA代码

代码语言:javascript
复制
'This loads the Ribbon Addin
Private Function LoadAddIn() As Boolean
    On Error GoTo Err_LoadAddIn
    Dim msg As String
    Dim m_addIn As COMAddIn
    Dim m_automationObject As Object
    Dim m_sWorkbookKey As String    

    msg = "Unable to load the PITA AddIn, please contact PITA support"

    'Load the Excel Addin
    Set m_addIn = Application.COMAddIns("PITA Ribbon")
    'Connect the COM Add-In to the current workbook
    m_addIn.Connect = True

    'Set a reference to the utility class that the COM Add-In references
    m_automationObject = m_addIn.Object
    'If it is nothing then the Add-In is in a bad state
    If m_automationObject Is Nothing Then
        msg = "Error loading the PITA AddIn, please contact PITA support"
        GoTo Err_LoadAddIn
    Else
        'Set the service type of the Add-In (currently only SQLServer)
        m_automationObject.SetDataConnection "SQLServer"
        'Set the workbook key - this is the name of the analyzer
        m_sWorkbookKey = Worksheets("SheetX").Range("A10")

        'Set the ribbon tab's visibility relative to the current workbook
        m_automationObject.SetTabVisibility m_sWorkbookKey, True

        'If the connection to the datasource is successful
        'Populate the Tab's List Controls with the values from SQL Server
        If m_automationObject.Connected = True Then
            m_automationObject.SetTabDefaults m_sWorkbookKey
        End If
    End If

    LoadAddIn = True
    Exit Function

Err_LoadAddIn:
    MsgBox msg, vbCritical, "AddIn load error"
    LoadAddIn = False
End Function

我曾尝试将下面自定义部分中的VSTO清单文件更改为"0“,但在尝试使用此修改进行安装时,ClickOnce安装程序出错。

代码语言:javascript
复制
    <vstov4:customization>
      <vstov4:appAddIn application="Excel" loadBehavior="0" keyName="PITA Ribbon">
        <vstov4:friendlyName>PITA Ribbon</vstov4:friendlyName>
        <vstov4:description>PITA Ribbon</vstov4:description>
        <vstov4.1:ribbonTypes xmlns:vstov4.1="urn:schemas-microsoft-com:vsto.v4.1">
          <vstov4.1:ribbonType name="PITAAddIn.PITARibbon, PITA Ribbon, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" />
        </vstov4.1:ribbonTypes>
      </vstov4:appAddIn>
    </vstov4:customization>

有没有办法让ClickOnce安装将默认加载行为设置为"0"?

任何关于如何做到这一点的指导都是非常感谢的!

EN

回答 2

Stack Overflow用户

发布于 2018-11-28 03:40:05

只要在发布后直接更改清单,就需要对部署进行重新签名。

MSDN documentation

One of my answers that has a powershell script that automates this

票数 0
EN

Stack Overflow用户

发布于 2018-11-28 03:44:12

Chris在初始帖子的评论部分提出的问题确定了核心问题(即,在将loadBehavior更改为0之后,您是否重新签署了部署?)

修改外接程序的清单文件后,必须对清单和程序集重新签名。

有关修改VSTO部署属性的说明,请参阅here

有关对程序集和部署清单进行重新签名的说明,请参阅here

生成自签名证书可以使用PowerShell完成,这是我用来为测试环境创建代码签名证书的link

我的步骤如下:

  • 使用PowerShell生成新的代码签名证书。komsky提供了一个很棒的命令行example
  • 发布VSTO外接程序后,使用LoadBehavior to 0
  • 对外接程序程序集清单进行修改以对清单mage.exe -sign "PITA Ribbon.dll.manifest -CertFile "C:\Certificates\cert.pfx -Password ******** -a sha256RSA
  • Use MAGE.EXE进行签名,以更新VSTO部署清单mage.exe -update "C:\PitaDeploy\Pita Ribbon.vsto" -appmanifiest "Pita Ribbon.dll.manifest" -CertFile "C:\Certificates\cert.pfx -Password ******* -a sha256RSA

执行这些步骤后,VSTO安装时没有任何问题。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/53290352

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档