Office 2003 VSTO add-in can run in debug mode but cannot load after installation

[Author: Fish Ge, Office/Project Support Team, Microsoft Asia Pacific Global Support Center]

[???: https://blogs.technet.com/b/officeasia/archive/2011/12/14/office2003-vsto.aspx]

Hope this article is helpful to VSTO and Office add-in developers.

 

Problem Description

You develop Office 2003 VSTO add-in using Visual Studio 2008. On developer machine you can run the add-in from Visual Studio in debug mode, however when the add-in is installed, it cannot load or the custom menus in add-in doesn't respond.

 

Solution

To troubleshoot add-in loading issue, we can follow https://msdn.microsoft.com/en-us/library/ms269003(v=VS.90).aspx to add environment variable VSTO_SUPPRESSDISPLAYALERTS=0 and VSTO_LOGALERTS=1. By this way, everytime the add-in fails to load there will be error message.  

 

Then let's see what prerequisites are needed for running Office 2003 VSTO add-in (http://msdn.microsoft.com/en-us/library/bb332051(office.12).aspx):

 

Table 1. Summary of bootstrapper packages that accompany the article

 

Bootstrapper package

Dependent packages

Other conditions

VSTO 2005 SE runtime

The .NET Framework 2.0

 

Visual Studio Tools for Office Language Pack

VSTO 2005 SE runtime

 

Primary interop assemblies redistributable package for the 2003 release of Office

.NET Framework 2.0

Installs all primary interop assemblies if Office 2003 is installed.

Primary interop assemblies redistributable package for the 2007 release of Office

.NET Framework 2.0

Installs all primary interop assemblies if the 2007 release of Office is installed.

 

 When we develop Office 2003 add-in in Visual Studio 2005, these prerequisites can be checked on in add-in's installation project properties. However Visual Studio 2008 only include prerequisites for Office 2007 add-ins, such as Visual Studio Tools for Office system 3.0 Runtime and Primary Interop Asseblies 2007. Lack of prerequisites for Office 2003 add-in will result in failure of loading.

   

Below are complete steps to deploy Office 2003 using Visual Studio 2008:

1. Download Microsoft Visual Studio 2005 Tools for Office SE Resources Visual Studio 2005 Tools for Office Second Edition Sample: Deploying Office Solutions Using Windows Installer Version 3

2. Visit “C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\packages”, copy VSTOSERuntime?Office2003PIA folder to”C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

3. Download Download VSTO 2005 SE Runtime https://www.microsoft.com/download/en/details.aspx?displaylang=en&id=2392, and copy to “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\VSTOSERuntime

4. Start Visual Studio 2008 command line, navigate to“C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\Projects\Checks”

5. Run the following command:

cl.exe /Oxs /MT /GS ComponentCheck.cpp advapi32.lib

6. When it is completed, we will see ComponentCheck.exe and ComponentCheck.obj

7. Copy ComponentCheck.exe to “C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\VSTOSERuntime”?C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages\Office2003PIA”

8. Right click setup project in Visual Studio 2008, and check on below in Prerequisites:

 

  • .NET Framework 2.0
  • Windows Installer 3.1
  • Microsoft Office 2003 Primary Interop Assemblies
  • Microsoft Visual Studio 2005 Tools for Office Second Edition runtime

9.  Follow https://msdn.microsoft.com/en-us/library/bb332052(v=office.12).aspx#officevstowindowsinstallerwalkthrough_creatinginstallerpackagestodeploysolutions, start from sectoin Adding a Custom Action to Grant Trust to the Assembly till To add a launch condition for the VSTO 2005 SE runtime

 

     1)      After add-in is installed, we need to use CASPOL.EXE (shipped with .NET Framework 2.0) to add trust level to all add-in files, otherwise the custom menu in the add-in may not respond. Load project ”C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\projects\SetSecurity

Modify CaspolSecurityPolicyCreator.cs from SetSecurity project:

 

To simplify the steps, replace original code by below part (the modified part is highlighted):

 

 

 

           // Add the solution code group. Grant no permission at this level.

 

            string arguments = policyLevel + " -q -ag " + parentCodeGroup + " -url \"" + solutionInstallationUrl + "\" FullTrust -n \"" + solutionCodeGroupName + "\" -d \"" + solutionCodeGroupDescription + "\"";

 

            try

 

            {

 

                RunCaspolCommand(frameworkFolder, arguments);

 

            }

 

            catch (Exception ex)

 

            {

 

                string error = String.Format("Cannot create the security code group '{0}'.", solutionCodeGroupName);

 

                throw new Exception(error, ex);

 

            }

 

 

 

            //// Add the assembly code group. Grant FullTrust permissions to the main assembly.

 

            //try

 

            //{

 

            // // Use the assembly strong name as the membership condition.

 

            // // Ensure that the assembly is strong-named to give it full trust.

 

            // AssemblyName assemblyName = Assembly.LoadFile(assemblyPath).GetName();

 

            // arguments = policyLevel + " -q -ag \"" + solutionCodeGroupName + "\" -strong -file \"" + assemblyPath + "\" \"" + assemblyName.Name + "\" \"" + assemblyName.Version.ToString(4) + "\" FullTrust -n \"" + assemblyCodeGroupName + "\" -d \"" + assemblyCodeGroupDescription + "\"";

 

 

 

            // RunCaspolCommand(frameworkFolder, arguments);

 

            //}

 

            //catch (Exception ex)

 

            //{

 

            // try

 

            // {

 

            // // Clean the solutionCodeGroupName.

 

            // RemoveSecurityPolicy(machinePolicyLevel, solutionCodeGroupName);

 

            // }

 

            // catch { }

 

 

 

            // string error = String.Format("Cannot create the security code group '{0}'.", assemblyCodeGroupName);

 

            // throw new Exception(error, ex);

 

            //}

In Custom Action, add Primary output from SetSecurity

    3) A sample of CustomActionData for Install is:

/assemblyName="<add-in name>.dll" /targetDir="[TARGETDIR]\" /solutionCodeGroupName="<corp name>.<add-in name>.dll" /solutionCodeGroupDescription="Code group for <add-in name>" /assemblyCodeGroupName="<add-in name>" /assemblyCodeGroupDescription="Code group for <add-in name>" /allUsers=[ALLUSERS]

   4) A sample of CustomActionData for Uninstall and Rollback is:

/solutionCodeGroupName="<corp name>.<add-in name>.dll"

    5) Add Launch Conditions

10. Recompile the add-in project adn installation project, then install the add-in to target machine. This add-in will load in both Office 2003 and 2007.

Follow-up Issues

If an Office 2003 add-in project develped in Visual Studio 2008 is opened in Visual Studio 2008 with Office 2007 installed, there will be upgrade notification. After upgrade, add-in reference against Office 2003 VSTO runtime and PIA will be changed to Office 2007 (version 11 to version 12). If we just compile the installation project and install the add-in, the add-in will not load.

The cause of the issue is that Office 2007 VSTO add-in will have Manifest in registry key like [TARGETDIR]<add-in name>.vsto|vstolocal, however the Office 2003 add-in will have Manifest in registry key like [TARGETDIR]<add-in name>.dll.manifest. There're two solutions (not backward compatible):

1. Create a new Office 2007 add-in project in Visual Studio 2008, and copy the add-in code from Office 2003 add-in project to the new one.

2. Add <add-in name>.dll.manifest and <add-in name>.vsto into add-in installatin project. We can right click installation project->Add->File, and include these two files:

 

Then right click installation project->View->Registry, find Manifest key, change [TARGETDIR]<add-in name>.dll.manifest to [TARGETDIR]<add-in name>.vsto|vstolocal

 

Rebuild the project and now the add-in can load in Office 2007. The drawback is that the add-in cannot load in Office 2003 anymore.

 

Similar issue is posted here: 

https://social.msdn.microsoft.com/Forums/en-US/vsto/thread/75dbff40-181b-434f-87fe-7fa7e21a5828

 

References

Deploying Visual Studio 2005 Tools for the Office System SE Solutions Using Windows Installer (Part 1 of 2)

https://msdn.microsoft.com/en-us/library/bb332051(office.12).aspx

 

Deploying Visual Studio 2005 Tools for the Office System SE Solutions Using Windows Installer: Walkthroughs (Part 2 of 2)

https://msdn.microsoft.com/en-us/library/bb332052(v=office.12).aspx

 

Troubleshooting COM Add-In load failures

https://blogs.msdn.com/b/vsod/archive/2008/04/22/troubleshooting-com-add-in-load-failures.aspx

 

VSOD (CSS) team blog:

Visual Studio Office Development (VSOD) Support Team

https://blogs.msdn.com/b/vsod/

 

VSTO (Product team) team blog:

Office Development with Visual Studio

https://blogs.msdn.com/b/vsto/