Link to home
Start Free TrialLog in
Avatar of EnolaKotrotsos
EnolaKotrotsos

asked on

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

Avatar of xenacode
xenacode
Flag of United Kingdom of Great Britain and Northern Ireland image

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
Avatar of EnolaKotrotsos
EnolaKotrotsos

ASKER

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)

And yes, sorry I mean the addin does not load
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.

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.
what value does the LoadBehavior key have?
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"
OK. Have you installed VSTO and the 2007 PIAs on the target machine?
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!
What are those Primary Interop Assemblies specifically?

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

Is there support for Vista?
Is it possible to check if PIA's are installed?
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
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.

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...
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.)
You mean re-installing office, ok sure? I do not see them in my references..
No. Re-install the PIAs.
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.
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.
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..


ASKER CERTIFIED SOLUTION
Avatar of xenacode
xenacode
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
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!

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