Partager via


Office2003的VSTO插件无法加载,但是在调试时正常

[??:??????, Office/Project????, ?????????????]

[English version: https://blogs.technet.com/b/officeasia/archive/2013/01/04/office-2003-vsto-add-in-can-run-in-debug-mode-but-cannot-load-after-installation.aspx]

?????VSTO??????Office??????????

????:

??Visual Studio 2008???Office 2003??(????add-in??),??????(?F5)??????????,????????????????????,????????,??????????/???????

???? :

???????????,?????https://msdn.microsoft.com/en-us/library/ms269003(v=VS.90).aspx ?????? VSTO_SUPPRESSDISPLAYALERTS=0 ? VSTO_LOGALERTS=1,????????????????(???????)????????????????

 

 

?????????Office2003?VSTO????????????(https://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.

 

 

 

????Visual Studio 2005??Office 2003???,???????????? ???? ??????????????????Visual Studio 2008??????Office 2007?????????,??Visual Studio Tools for Office system 3.0 Runtime?Primary Interop Asseblies 2007?,???Office 2003?????????,??????????????

 

 

 

????????Visual Studio 2008??Office 2003????:

1. ??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. ??“C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\packages”,??VSTOSERuntime?Office2003PIA????”C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bootstrapper\Packages

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

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

5. ??????:

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

6.?????, ???ComponentCheck.exe?ComponentCheck.obj

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

8.????setup??,?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. ??https://msdn.microsoft.com/en-us/library/bb332052(v=office.12).aspx#officevstowindowsinstallerwalkthrough_creatinginstallerpackagestodeploysolutions ,?Adding a Custom Action to Grant Trust to the Assembly???????,??To add a launch condition for the VSTO 2005 SE runtime

 

     1)      ?????,???????????,???.NET Framework 2.0??CASPOL.EXE??????????????,??????????????????? ”C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\projects\SetSecurity”??

??SetSecurity????CaspolSecurityPolicyCreator.cs:

 

????????(??????),????????????(???????????):

 

  

 

           // 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);

 

            //}

Custom Action???Primary output from SetSecurity

    3) Install???CustomActionData????:

/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) Uninstall?Rollback???CustomActionData????:

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

    5) ??Launch Conditions

10. ????????? ???? ??,?????????????????????Office 2003?2007?????

???? :

??????????(Visual Studio 2008 + Office 2003??????????)?Visual Studio 2008 + Office 2007?????,????????????,???????Office 2003?VSTO runtime?PIA????????Office 2007???????? ???? ????????,?????????

??????????Office 2007?????????Manifest?????[TARGETDIR]<add-in name>.vsto|vstolocal,?Office 2003???Manifest?????[TARGETDIR]<add-in name>.dll.manifest???????????:

1. ????Office 2007?????,????????????

2. ?????????????<add-in name>.dll.manifest?<add-in name>.vsto,??????????->Add->File,????????

 

?????????->View->Registry,??Manifest,???[TARGETDIR]<add-in name>.dll.manifest,???[TARGETDIR]<add-in name>.vsto|vstolocal

 

 

???????,?Office 2007??????????????????Office 2003????

 

???????:

 

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

???? :

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/