我用VS2015开发了一个词:2016VSTO,并使用InstallShield部署到Windows 10机器上。如果我将LoadBehavior设置为3,它将加载并正常工作。
我需要的是按需装载。我尝试过将LoadBehavior设置为9,但没有骰子。创建Word文档(最终加载VSTO)的web应用程序最初是为Word 2010编写的,并将VSTO路径嵌入到Word文档中,并添加了GUID (C:\myAddIn.vsto|GUID|vstolocal)。当VSTO试图加载时,打开Word 2016中由web应用程序创建的文档会引发此错误:
Microsoft.VisualStudio.Tools.Applications.Runtime.CannotCreateStartupObjectException:无法创建启动对象myAddin.ThisAddIn的实例
我为do 2013/2015所见的任何教程都不引用在VSTO路径中嵌入GUID;只需将LoadBehavior设置为9即可。
文件-> Options ->AddIns中没有列出发行者。VSTO列在非活动AddIns下,我希望它在按需加载之前。
任何帮助都是非常感谢的。
发布于 2018-03-02 16:51:22
如果您希望代码只在某些文档中执行,如您描述的(从注释中)
我只希望AddIn为web应用程序创建的Word文档加载。“开始”菜单中的“开场白”不应加载AddIn。
那么,与其使用外接程序,不如使用文档级自定义。
附加到文档级自定义的代码将随文档一起加载,并在文档关闭时卸载。可以创建文档级别的自定义并分发文档,或者在以后使用VSTO的ServerDocument类附加代码。
因为在您的示例中,文档是由web应用程序生成的,所以使用ServerDocument表示。
以下是MSDN文章的主要内容:
=============================================
将托管代码扩展附加到文档
Microsoft.VisualStudio.Tools.Applications.ServerDocument.dll和Microsoft.VisualStudio.Tools.Applications.Runtime.dll assemblies的引用。using Microsoft.VisualStudio.Tools.Applications; using Microsoft.VisualStudio.Tools.Applications.Runtime;下面的代码示例使用AddCustomization重载。此重载采用文档的完整路径和Uri,该Uri指定要附加到文档的自定义部署清单的位置。本例假设桌面上有一个名为WordDocument1.docx的Word文档,并且部署清单位于桌面上的一个名为发布的文件夹中。
string documentPath = System.Environment.GetFolderPath(
Environment.SpecialFolder.Desktop) + @"\WordDocument1.docx";
int runtimeVersion = 0;
try
{
runtimeVersion = ServerDocument.GetCustomizationVersion(documentPath);
// Make sure that this document does not yet have any Visual Studio Tools
// for Office customizations.
if (runtimeVersion == 0)
{
string deployManifestPath = System.Environment.GetFolderPath(
Environment.SpecialFolder.Desktop) + @"\Publish\WordDocument1.vsto";
Uri deploymentManifestUri = new Uri(deployManifestPath);
ServerDocument.AddCustomization(documentPath, deploymentManifestUri);
System.Windows.Forms.MessageBox.Show("The document was successfully customized.");
}
else
{
System.Windows.Forms.MessageBox.Show("The document is already customized.");
}
}
catch (FileNotFoundException)
{
System.Windows.Forms.MessageBox.Show("The specified document does not exist.");
}
catch (DocumentNotCustomizedException ex)
{
System.Windows.Forms.MessageBox.Show("The document could not be customized.\n" +
ex.Message);
}发布于 2018-03-02 15:26:34
你试过把LoadBehaviour设置为0x10 => Load first time, then load on demand吗?这将使Office在第一次执行它时加载您的加载项并在内部缓存它。然后将值更改为0x9..。随后,该应用程序将按需加载。
https://stackoverflow.com/questions/49072140
复制相似问题