Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

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

Posted on 2009-04-14
25
1,449 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
ID: 24145616
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
ID: 24145630
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
ID: 24145654
And yes, sorry I mean the addin does not load
0
How Do You Stack Up Against Your Peers?

With today’s modern enterprise so dependent on digital infrastructures, the impact of major incidents has increased dramatically. Grab the report now to gain insight into how your organization ranks against your peers and learn best-in-class strategies to resolve incidents.

 
LVL 1

Author Comment

by:EnolaKotrotsos
ID: 24145782
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
ID: 24145813
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
ID: 24145825
what value does the LoadBehavior key have?
0
 
LVL 1

Author Comment

by:EnolaKotrotsos
ID: 24145887
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
ID: 24145895
OK. Have you installed VSTO and the 2007 PIAs on the target machine?
0
 
LVL 6

Expert Comment

by:xenacode
ID: 24145899
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
ID: 24145900
What are those Primary Interop Assemblies specifically?

0
 
LVL 6

Expert Comment

by:xenacode
ID: 24145940
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
ID: 24146051
Is there support for Vista?
0
 
LVL 1

Author Comment

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

Expert Comment

by:xenacode
ID: 24146104
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
ID: 24146125
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
ID: 24146140
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
ID: 24146194
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
ID: 24149281
You mean re-installing office, ok sure? I do not see them in my references..
0
 
LVL 6

Expert Comment

by:xenacode
ID: 24149407
No. Re-install the PIAs.
0
 
LVL 1

Author Comment

by:EnolaKotrotsos
ID: 24149454
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
ID: 24149732
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
ID: 24151310
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
ID: 24156581
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
ID: 24156657
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
ID: 24156812
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

Resolve Critical IT Incidents Fast

If your data, services or processes become compromised, your organization can suffer damage in just minutes and how fast you communicate during a major IT incident is everything. Learn how to immediately identify incidents & best practices to resolve them quickly and effectively.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

A theme is a collection of property settings that allow you to define the look of pages and controls, and then apply the look consistently across pages in an application. Themes can be made up of a set of elements: skins, style sheets, images, and o…
Using Word 2013, I was experiencing some incredible lag when typing.  Here's what worked for me....
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.
In a previous video Micro Tutorial here at Experts Exchange (http://www.experts-exchange.com/videos/1358/How-to-get-a-free-trial-of-Office-365-with-the-Office-2016-desktop-applications.html), I explained how to get a free, one-month trial of Office …

791 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