gpt4 book ai didi

c# - 从 Office 本身更新 ClickOnce VSTO 加载项不会更新加载项

转载 作者:太空狗 更新时间:2023-10-29 19:46:32 28 4
gpt4 key购买 nike

我在功能区上有一个按钮来检查 AddIn(本身)更新

这是代码

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");
}
}
}

发生的事情是我收到“完成”消息框,但在重新启动 Excel 后,插件实际上没有更新并且我无法再次更新它,因为下次我单击相同的按钮,ApplicationDeployment.IsNetworkDeployed 返回 false

我该如何解决这个问题?

最佳答案

我相信可以在这篇 MSDN 帖子中找到答案:VSTO, ClickOnce and auto update

节选:

This is True: VSTO applications are ClickOnce applications

This is not True: The ClickOnce API is supported by VSTO applicationsWhy: While VSTO Applications are ClickOnce applications, they require functionality that extends the base implementation of ClickOnce. A product of this requirement is that not everything within ClickOnce (for Windows Forms) applies to VSTO. One of these specific areas is the Runtime API.

This is True: Some parts of the API will workWhy: Because the VSTO Runtime Uses the core part of ClickOnce, some parts actually will function. 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.

This is not True: You can use the API to Download an updateWhy: This goes back to the ClickOnce/VSTO difference. If you imagine ClickOnce as this sort of generic technology, you can think of VSTO as a specific implementation of it. In most cases (specifically Winforms applications) the generic technology does everything that is required. 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). 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. 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. It is the VSTO Runtime that does these steps.

他提到了一篇博文,我相信是这篇:Click-Once forced updates in VSTO: Some things we don’t recommend using, that you might consider anyway.

节选:

//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();

它不完全是生产就绪代码,但您明白了。

关于c# - 从 Office 本身更新 ClickOnce VSTO 加载项不会更新加载项,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39619047/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com