Solved

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

Posted on 2009-04-14
25
1,443 Views
Last Modified: 2013-11-10
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
Comment
Question by:EnolaKotrotsos
  • 13
  • 12
25 Comments
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
And yes, sorry I mean the addin does not load
0
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
what value does the LoadBehavior key have?
0
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
OK. Have you installed VSTO and the 2007 PIAs on the target machine?
0
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
What are those Primary Interop Assemblies specifically?

0
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
Is there support for Vista?
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
Is it possible to check if PIA's are installed?
0
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
You mean re-installing office, ok sure? I do not see them in my references..
0
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
No. Re-install the PIAs.
0
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 6

Accepted Solution

by:
xenacode earned 500 total points
Comment Utility
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
 
LVL 1

Author Comment

by:EnolaKotrotsos
Comment Utility
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
 
LVL 6

Expert Comment

by:xenacode
Comment Utility
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

Enabling OSINT in Activity Based Intelligence

Activity based intelligence (ABI) requires access to all available sources of data. Recorded Future allows analysts to observe structured data on the open, deep, and dark web.

Join & Write a Comment

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Today I had a very interesting conundrum that had to get solved quickly. Needless to say, it wasn't resolved quickly because when we needed it we were very rushed, but as soon as the conference call was over and I took a step back I saw the correct …
The viewer will learn how to make their project stand out over others by learning how to change colors and shapes, add spaces, change directions, and add bullets to their charts.
This Experts Exchange video Micro Tutorial shows how to tell Microsoft Office that a word is NOT spelled correctly. Microsoft Office has a built-in, main dictionary that is shared by Office apps, including Excel, Outlook, PowerPoint, and Word. When …

728 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now