简体   繁体   English

从Office本身更新ClickOnce VSTO加载项不会更新该加载项

[英]Updating ClickOnce VSTO AddIn from within the Office itself does not update the AddIn

I have a button on a ribbon to check for AddIn (itself) updates 我在功能区上有一个按钮来检查AddIn(自身)更新

Here's the code 这是代码

private void button1_Click(object sender, RibbonControlEventArgs e)
{
    UpdateCheckInfo info = null;

    if (ApplicationDeployment.IsNetworkDeployed)
    {
        ApplicationDeployment ad = ApplicationDeployment.CurrentDeployment;
        var appId = new ApplicationIdentity(ad.UpdatedApplicationFullName);
        var unrestrictedPerms = new PermissionSet(PermissionState.Unrestricted);
        var appTrust = new ApplicationTrust(appId)
        {
            DefaultGrantSet = new PolicyStatement(unrestrictedPerms),
            IsApplicationTrustedToRun = true,
            Persist = true
        };

        ApplicationSecurityManager.UserApplicationTrusts.Add(appTrust);

        info = ad.CheckForDetailedUpdate();

        if (info.UpdateAvailable)
        {
            ad.Update();
            MessageBox.Show("DONE");
        }
    }
}

What happens is I get the "DONE" message box but after restarting the Excel, the addin is actually not updated and I can't update it again because the next time I click the same button, the ApplicationDeployment.IsNetworkDeployed returns false . 发生了什么事,我得到了“ DONE”消息框,但是在重新启动Excel之后,该加载项实际上并未更新因此无法再次更新它,因为下次单击同一按钮时, ApplicationDeployment.IsNetworkDeployed返回false

How can I fix this? 我怎样才能解决这个问题?

I believe the answer can be found in this MSDN post: VSTO, ClickOnce and auto update 我相信答案可以在以下MSDN帖子中找到: VSTO,ClickOnce和自动更新

An excerpt: 摘录:

This is True : VSTO applications are ClickOnce applications 这是真的 :VSTO应用程序是ClickOnce应用程序

This is not True : The ClickOnce API is supported by VSTO applications Why : While VSTO Applications are ClickOnce applications, they require functionality that extends the base implementation of ClickOnce. 这不是正确的 :VSTO应用程序支持ClickOnce API。 原因 :VSTO应用程序是ClickOnce应用程序时,它们需要扩展ClickOnce基本实现的功能。 A product of this requirement is that not everything within ClickOnce (for Windows Forms) applies to VSTO. 此要求的产物是,并非ClickOnce(适用于Windows窗体)中的所有内容都适用于VSTO。 One of these specific areas is the Runtime API. 这些特定领域之一是Runtime API。

This is True : Some parts of the API will work Why : Because the VSTO Runtime Uses the core part of ClickOnce, some parts actually will function. 这是正确的 :API的某些部分可以工作原因 :由于VSTO运行时使用ClickOnce的核心部分,因此某些部分实际上可以运行。 What is not known is where exactly this line is drawn. 还不知道确切地画出这条线的地方。 I have found as very loose general rule of thumb: anything that doesn't change the state of the application (anything that provides you with "information") will likely work. 我发现一般的经验法则很宽松:任何不会改变应用程序状态的东西(任何为您提供“信息”的东西)都可能会起作用。 This is why my blog post describes how to use the API to "check" for the update but uses the VSTOInstaller exe to do the actual act of updating. 这就是为什么我的博客文章描述了如何使用API​​来“检查”更新,但是使用VSTOInstaller exe来执行更新的实际操作。

This is not True : You can use the API to Download an update Why : This goes back to the ClickOnce/VSTO difference. 这不是正确的 :您可以使用API​​下载更新。 原因 :这可以追溯到ClickOnce / VSTO的区别。 If you imagine ClickOnce as this sort of generic technology, you can think of VSTO as a specific implementation of it. 如果您将ClickOnce想象为这种通用技术,则可以将VSTO视为它的特定实现。 In most cases (specifically Winforms applications) the generic technology does everything that is required. 在大多数情况下(特别是Winforms应用程序),通用技术可以完成所需的一切。 For VSTO though, we needed to extend the technology to make it do stuff it had never done before (specifically register customizations with office and maintain some data need to setup entrypoints and whatnot). 但是,对于VSTO,我们需要扩展技术以使其能够做以前从未做过的事情(特别是在Office中注册自定义项,并维护一些数据来设置入口点等)。 As such the generic technology doesn't provide all of the functionality we need. 因此,通用技术无法提供我们需要的所有功能。 In this specific case incurring an update changes the state of the application in such a way that we have to change some of the registration information for Office. 在这种特定情况下,进行更新会更改应用程序的状态,因此我们必须更改Office的某些注册信息。 ClickOnce "doesn know" enough to update these values, and as such isn't capable (in its current state) of doing a "correct" update of a VSTO application. ClickOnce“不知道”足以更新这些值,因此无法(在当前状态下)对VSTO应用程序进行“正确”更新。 It is the VSTO Runtime that does these steps. 完成这些步骤的是VSTO运行时。

He mentions a blog post, which I believe is this one: Click-Once forced updates in VSTO: Some things we don't recommend using, that you might consider anyway. 他提到了一篇博客文章,我相信这是一篇文章: VSTO中的Click-Once强制更新:我们建议您不要考虑使用某些不建议使用的方法。

An excerpt: 摘录:

//Call VSTOInstaller Explicitely in "Silent Mode"
string installerArgs = " /S /I \\\\GenericServer\\WordDocument2.vsto";
string installerPath = "C:\\Program Files\\Common Files\\microsoft 
shared\\VSTO\\9.0\\VSTOINSTALLER.exe";

System.Diagnostics.Process VstoInstallerProc = new System.Diagnostics.Process();
VstoInstallerProc.StartInfo.Arguments = installerArgs;
VstoInstallerProc.StartInfo.FileName = installerPath;
VstoInstallerProc.Start();
VstoInstallerProc.WaitForExit();

It's not exactly production-ready code, but you get the idea. 它不是完全可以用于生产的代码,但是您可以理解。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM