[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1468
  • Last Modified:

Word 2007 VSTO Add-in works perfectly when debugging, but not when setup deployed

Goodevening.

I have got a Word 2007 Custom action pane. That works perfectly when debugging it in VS. But somehow I can't seem the get it to work through setup.

I have added a setup project, and ran through the usual steps like adding primary output etc. But after running setup- the action pane doesn't pop up...

Can someone take a look at the code below (from ThisAddIn.cs) and see if there is some particular reason? Is it also possible to 'run' the generated add-in dll from within Word?

Thank you very much.
using System;
using System.Windows.Forms;
using Microsoft.VisualStudio.Tools.Applications.Runtime;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using Microsoft.Office.Tools;
using Microsoft.Office.Tools.Word;
 
namespace Word_2007_Pane
{
    public partial class ThisAddIn
    {
        CustomTaskPane pane;
        public Word.ApplicationClass word;
        Office.CommandBarButton button;
        PaneUserControl userControl;
        private void ThisAddIn_Startup(object sender, System.EventArgs e)
        {
            word = (Word.ApplicationClass)Application;
            word.ApplicationEvents3_Event_NewDocument += new Microsoft.Office.Interop.Word.ApplicationEvents3_NewDocumentEventHandler(word_ApplicationEvents3_Event_NewDocument);
 
            userControl = new PaneUserControl();
            pane = (CustomTaskPane)this.CustomTaskPanes.Add(userControl, "Research");
 
            pane.Visible = true; 
 
            // Create CommandBarButton
            button = (Office.CommandBarButton)word.CommandBars["Standard"].Controls.Add(Office.MsoControlType.msoControlButton, missing, missing, missing, missing);
            button.Caption = "Office Suggest";
            button.Tag = "Office Suggest";
            button.FaceId = 255;
            button.Style = Microsoft.Office.Core.MsoButtonStyle.msoButtonIconAndCaption;
            button.Visible = true;
 
            button.Click += new Microsoft.Office.Core._CommandBarButtonEvents_ClickEventHandler(button_Click);
               
        }
 
        void button_Click(Microsoft.Office.Core.CommandBarButton Ctrl, ref bool CancelDefault)
        {
            try
            {
                pane.Visible = true;
            }
            catch
            {
 
            }
            //throw new Exception("The method or operation is not implemented.");
        }
 
        Word.DocumentClass document;
        void word_ApplicationEvents3_Event_NewDocument(Microsoft.Office.Interop.Word.Document Doc)
        {
            try
            {
                document = (Word.DocumentClass)Doc;
                pane.Visible = true;
               // userControl.Activate();
            }
            catch
            {
            }
        }
 
        private void ThisAddIn_Shutdown(object sender, System.EventArgs e)
        {
            this.CustomTaskPanes.Remove(pane);
        }
 
 
 
        #region VSTO generated code
 
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        private void InternalStartup()
        {
            this.Startup += new System.EventHandler(ThisAddIn_Startup);
            this.Shutdown += new System.EventHandler(ThisAddIn_Shutdown);
        }
 
        #endregion
    }
}

Open in new window

0
EnolaKotrotsos
Asked:
EnolaKotrotsos
  • 13
  • 12
1 Solution
 
xenacodeCommented:
Hi,

My first question is what do you mean when you say it does not work i.e. does the add-in load at all? If not, have you created the necessary registry entries in your setup project? Visual Studio creates these for you automatically when you run a VSTO project in debug mode but you need to create them on the target machine at install.

Pete
0
 
EnolaKotrotsosAuthor Commented:
Hi, is it possible to capture these registry settings? So I can copy those?

(can probably just try to see what happens when running I suppose. but I can't just now)

0
 
EnolaKotrotsosAuthor Commented:
And yes, sorry I mean the addin does not load
0
Fill in the form and get your FREE NFR key NOW!

Veeam is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

 
EnolaKotrotsosAuthor Commented:
I got a quick hold of the dev pc. I copied the key's from the dev pc to the test pc. (They were under HKCU) First I copied those from there to HKLM on the test pc, did not do anything- then to HKCU, did not do anything either.

0
 
xenacodeCommented:
OK. Start with HKCU\Software\Microsoft\Office\Word\Addins\[your addin name]

These entries tell Office to load the add-in on startup and you can copy these from your debug machine.
0
 
xenacodeCommented:
what value does the LoadBehavior key have?
0
 
EnolaKotrotsosAuthor Commented:
3

this is the contents of an export of the reg key

\\Windows Registry Editor Version 5.00

[HKEY_CURRENT_USER\Software\Microsoft\Office\Word\Addins\Word 2007 Pane]
"CommandLineSafe"=dword:00000001
"Description"="Word 2007 Pane -- an addin created with VSTO technology"
"FriendlyName"="Word 2007 Pane"
"LoadBehavior"=dword:00000003
"Manifest"="C:\\BRG\\OfficeSuggest\\Word 2007 Pane\\Word 2007 Pane\\bin\\Debug\\Word 2007 Pane.dll.manifest"
0
 
xenacodeCommented:
OK. Have you installed VSTO and the 2007 PIAs on the target machine?
0
 
xenacodeCommented:
Hang on - I see a problem!

The Manifest key should contain the path to the manifest file on the target machine not on your debug machine!
0
 
EnolaKotrotsosAuthor Commented:
What are those Primary Interop Assemblies specifically?

0
 
xenacodeCommented:
These are the libraries that your VSTO application needs to access Office objects. Install these on your build machine and reference the PIAs instead of the Office dlls. Install on the target machine before installing your VSTO app.

You can get the PIA msi here:

http://www.microsoft.com/downloads/details.aspx?displaylang=en&FamilyID=59daebaa-bed4-4282-a28c-b864d8bfa513

0
 
EnolaKotrotsosAuthor Commented:
Is there support for Vista?
0
 
EnolaKotrotsosAuthor Commented:
Is it possible to check if PIA's are installed?
0
 
xenacodeCommented:
Yes you can install VSTO applications on Vista. Obviously there are deployment issues relating to Vista where UAC is turned on but that's a different subject.

You can check if PIAs are installed by looking in C:\Windows\assembly. Look out for Microsoft.Office.Interop.Word version 12.0.0.0 etc.

One more thing to check (well actually there are several) - have you dealt with Code Access Security in the installation? VSTO add-ins normally require a CAS policy to be created. You will notice the LoadBehavior key change from 3 to 2 on starting Word if CAS is an issue. (Although many different problems can cause the load behaviour to change.)

Pete
0
 
EnolaKotrotsosAuthor Commented:
I see the pia's in /assembly, however- I can't seem to reference them in VS. Is there a special way to do it? They don't appear in the .NET tab.

0
 
EnolaKotrotsosAuthor Commented:
hm, wait..also- the version on VISTA (where i'm developing now) is a different language then the one on the test machine (which is XP) that could also pose a problem I suppose...
0
 
xenacodeCommented:
If the PIAs have been installed properly, you should see them in the .Net tab of the Add Reference dialog - they will appear as Microsoft.Office.Interop.Word etc. If you don't see them, try uninstalling and re-installing.

It's OK to build on Vista and deploy to XP. You do need the same version of Office and the same version of the PIAs. (It is technically possible to deploy components built against a different version of the PIAs but let's not go there just now.)
0
 
EnolaKotrotsosAuthor Commented:
You mean re-installing office, ok sure? I do not see them in my references..
0
 
xenacodeCommented:
No. Re-install the PIAs.
0
 
EnolaKotrotsosAuthor Commented:
I tried to install the runtime (using the url you provided) but it isn't supported for Vista, and I didn't find anything else. Any ideas?
 Thanks so far for your help by the way. I really appreciate it.
0
 
xenacodeCommented:
I think the exe at that url is just a self-extracting zip thing. It should run on Vista. When extracted, hopefully there will be an msi file to run to install the PIAs. You can't build and deploy VSTO add-ins without the PIAs so this is an essential step.
0
 
EnolaKotrotsosAuthor Commented:
when running the msi, it just disapears, that's the thing...after about 50 percent through the process...I will try and figure that out tomorrow why..


0
 
xenacodeCommented:
I think you have multiple problems here and unfortunately I don't have time just now to fix all of them. Your original problem was that your VSTO Word add-in would not run on the machine upon which you deployed it. This was due to a number of isues, including missing registry entries, no VSTO installation and no PIA installation. The fact that you are having trouble installing PIAs on your development machine is a new issue. Can you close this thread (preferably saying that I have answered your questions) and start a new thread if you are still having problems with installation?

Thanks,

Pete
0
 
EnolaKotrotsosAuthor Commented:
Your right, I will run through all the things you said- close this and give you the points. Thank you very m uch so far, and if I run into something new I will open a new thread!

0
 
xenacodeCommented:
Thanks very much. Creating VSTO add-ins is actually a lot more complex than would first appear. There's a new book out recently by Eric Carter & Eric Lippert called Visual Studio Tools for Office 2007 which may be useful. The official VSTO website also has some useful links:

http://msdn.microsoft.com/en-gb/vsto/default.aspx

Good luck,

Pete
0

Featured Post

Get your Disaster Recovery as a Service basics

Disaster Recovery as a Service is one go-to solution that revolutionizes DR planning. Implementing DRaaS could be an efficient process, easily accessible to non-DR experts. Learn about monitoring, testing, executing failovers and failbacks to ensure a "healthy" DR environment.

  • 13
  • 12
Tackle projects and never again get stuck behind a technical roadblock.
Join Now