C# .NET - How to Setup a MS Office 2007 Excel Add-In ?

Asked By Jipin M
12-Sep-11 01:28 AM
Hi all........, 

I Have been created a plug-in for Excel 2007. 
How I create its setup file? 
(Install as a plug-in for Excel) 
Solution developed in VS 2008

Regards.......
  Web Star replied to Jipin M
12-Sep-11 02:09 AM

This section describes how to create a Windows Installer package for Excel or Word document-based solutions. Although the example shows you how to deploy an Excel solution, you can use the same steps to deploy a Word solution. To perform this walkthrough, your development computer needs to have Office 2003 installed with VSTO 2005 SE. However, you can install the solution on a computer that has Office 2007 installed.

This walkthrough shows how to perform the following steps:

  • Create a Setup project that you can use to build the bootstrapper and the Windows Installer package.

  • Modify the Setup project so that the Windows Installer file installs your VSTO 2005 SE solution.

  • Add the prerequisites.

  • Add a custom action to grant security trust to the customization assembly.

  • Add a custom action to edit the application manifest that is embedded in the solution document.

Creating the Project

In this step, you create an Excel Workbook project in Visual C#.

To create a new project

  1. Create an Excel Workbook project in Visual C# with the name ExcelApplication.

  2. Verify that you have selected Create a new document.

    Visual Studio opens the new Excel workbook in the designer and adds the ExcelApplication project to Solution Explorer.

Signing the Assembly

Later in this article, you grant trust to the customization assembly based on a strong name and the assembly location. Before you can grant trust, you must sign the assembly.

To sign the assembly

  1. In Solution Explorer, right-click ExcelApplication, and then click Properties.

  2. Click the Signing tab.

  3. Select the Sign the assembly check box.

  4. In the Choose a strong name key file list, click <New. . .>.

  5. Type ExcelApplication in the Key file name box.

  6. Type a password in the Enter password and Confirm password boxes.

  7. Click OK.

  8. Close the Properties page.

Adding Code Behind the Workbook

In this step, you add a message box to the Microsoft.Office.Tools.Excel.Workbook.Startup event handler of the workbook. This enables you to verify that the solution is working when you open the document.

To add a message box to an initialization event

  1. In Solution Explorer, right-click ThisWorkbook.cs, and then click View Code.

  2. Add the following code to the ThisWorkbook_Startup event handler inside the ThisWorkbook class to show a message box during initialization.

    private void ThisWorkbook_Startup(object sender, System.EventArgs e)
    {
      MessageBox.Show("The document has been deployed successfully.");
    }
    
  3. Press F5 to run the project.

    Excel starts and the message box appears.

  4. Close the message box, and then exit Excel.

Creating a Setup Project

In this step, you create a Setup project that you can compile to create a Windows Installer file for your solution.

To create a Setup project for your solution

  1. In Solution Explorer, right-click Solution, point to Add, and then click New Project.

    The Add New Project dialog box appears.

  2. In the Project Types pane, expand Other Project Types, and then select Setup and Deployment.

  3. In the Templates pane, select Setup project.

  4. Name the project ExcelApplicationSetup.

  5. Click OK.

The Setup project appears in Solution Explorer. By default, the Windows Installer file that you build by using this Setup project includes a dialog box that enables the user to specify the installation location of the solution.

Adding the Workbook and Solution Assembly to the Setup Project

In this step, you add the primary output of the ExcelApplication project to the Setup project. The primary output of the ExcelApplication project consists of the workbook and the solution assembly.

To add the workbook and assembly to the Setup project

  1. In Solution Explorer, right-click ExcelApplicationSetup.

  2. Point to View on the shortcut menu, and then click File System.

  3. Right-click Application Folder in the left pane.

  4. Point to Add on the shortcut menu, and then click Project Output.

  5. In the Project box, select ExcelApplication.

  6. In the list of output types, select Primary output.

  7. Click OK.

    The project output and dependencies appear in the right pane.

When you add the primary output of a project to the Setup project, Visual Studio detects the dependencies. These dependencies can appear as a list of separate DLLs. Next, exclude these DLL dependencies, because they are part of the prerequisite packages and you add the packages as dependencies later.

To exclude the DLL dependencies

  1. In Solution Explorer, under the ExcelApplicationSetup node, expand Detected Dependencies.

  2. Right-click every dependency except Microsoft .NET Framework, and then click Exclude.

Adding the Prerequisites to the Setup Project

This step assumes you have prepared your development environment as described in http://msdn.microsoft.com/en-us/library/bb332051(v=office.12).aspx.

There are two ways to start the setup process:

  • Setup.exe

    When Setup.exe runs, the bootstrapper executes first. It examines the list of prerequisites needed by the application and installs them if necessary. After the prerequisites are installed, the .msi file is processed, which performs the actual installation of the application.

    Bb332052.Important(en-us,office.12).gifImportant:
    Users require administrative rights to install these prerequisites. If they do not have those rights, you must find another method of deployment, such as group policy or system management software (SMS).

  • An .msi file

    When this executable file launches, the bootstrapper does not execute and the prerequisites are not installed. However, it is possible to add launch conditions that prevent installation when the prerequisites are not present.

Add the prerequisites that the bootstrapper installs. You add launch conditions in a later step.

To add the prerequisites

  1. In Solution Explorer, right-click ExcelApplicationSetup.

  2. Click Properties.

  3. In the Property Pages dialog box, click Prerequisites.

  4. In the list of prerequisites, select the following items:

    • Microsoft Office 2003 Primary Interop Assemblies

    • 2007 Microsoft Office Primary Interop Assemblies

    • Microsoft Visual Studio Tools for Office SE Runtime

  5. Select Microsoft Visual Studio 2005 Tools for Office Runtime Language Pack, if any users run your solutions with non–English settings for Microsoft Windows.

    These users must have the Visual Studio 2005 Tools for Office Language Pack to see runtime messages in the same language as Windows.

  6. Click OK twice.

Adding a Custom Action to Grant Trust to the Assembly

Before a Visual Studio Tools for Office solution can run, the customization assembly must have FullTrust permissions. The sample custom action included in the source code that accompanies this article demonstrates how to grant permissions to the assembly that is installed on the user's computer.

To add the custom action project to the solution

  1. Using Windows Explorer, copy the SetSecurity project from the {SamplesDir}\projects directory to the directory that contains the ExcelApplication solution.

    Bb332052.Tip(en-us,office.12).gifTip:
    By default, the {SamplesDir} directory is C:\Program Files\Microsoft Visual Studio 2005 Tools for Office SE Resources\VSTO2005SE Windows Installer Sample Version 3\

  2. In Solution Explorer, right-click ExcelApplication.

  3. Point to Add on the shortcut menu, and then click Existing Project.

  4. Select the SetSecurity project.

  5. Click OK.

  6. In Solution Explorer, right-click the SetSecurity project, and then click Build.

To add the primary output of the custom action project to the Setup project

  1. In Solution Explorer, right-click ExcelApplicationSetup.

  2. Point to View on the shortcut menu, and then click Custom Actions.

  3. In the Custom Actions editor, right-click the Custom Actions node, and then click Add Custom Action.

  4. In the Look In list, click Application Folder, and then click Add Output.

    The Add Project Output Group dialog box opens.

  5. In the Project list, click SetSecurity.

  6. In the list of output types, select Primary output, and then click OK.

  7. Verify that Primary output from SetSecurity (Active) is in the list of primary outputs for the Setup project, and then click OK.

To add the custom action data for the Install method

  1. In the Custom Actions editor, expand Install.

  2. Right-click Primary output from SetSecurity (Active), and then click Properties Window.

  3. In the Properties window, set the CustomActionData property to the following string. Enter this as one long string, and changeMyCompanyName to your company name.

    /assemblyName="ExcelApplication.dll" /targetDir="[TARGETDIR]\"
       /solutionCodeGroupName="MyCompanyName.ExcelApplication"
       /solutionCodeGroupDescription="Code group for ExcelApplication"
       /assemblyCodeGroupName="ExcelApplication"
       /assemblyCodeGroupDescription="Code group for ExcelApplication"
       /allUsers=[ALLUSERS]
    
Bb332052.Tip(en-us,office.12).gifTip:
You do not need to add extra quotation marks if your company name contains a space.

To add the custom action data for the Rollback method

  1. In the Custom Actions editor, expand Rollback.

  2. Right-click Primary output from SetSecurity (Active), and then click Properties Window.

  3. In the Properties window, set the CustomActionData property to the following string:

    /solutionCodeGroupName="MyCompanyName.ExcelApplication"
    

To add the custom action data for the Uninstall method

  1. In the Custom Actions editor, expand Uninstall.

  2. Right-click Primary output from SetSecurity (Active), and then click Properties Window.

  3. In the Properties window, set the CustomActionData property to the following string:

    /solutionCodeGroupName="MyCompanyName.ExcelApplication"
    
Bb332052.note(en-us,office.12).gifNote:
Although the custom action does not override the Commit method, the base Windows Installer class provides an implementation. Thus, you must still call the method. However, it does not require any custom action data.

Adding a Custom Action to Update the Location of the Assembly

When you pressed F5 earlier to run your project, the build process edited the application manifest embedded in the workbook to point to the relative path of the assembly. If the workbook and the assembly remain in the same folder after installation, then you do not have to modify the embedded application manifest, and you can ignore this section. However, if you do want to enable the user to move the workbook to a different folder after installation, then you must edit the application manifest to point to the full path of the assembly. This is especially important for Excel template projects and Word template projects because the workbook or document created from a template typically resides in a location that is different from the template location.

A sample custom action has been created for you. Add this custom action to the Setup project.

To add the custom action project to the solution

  1. Using Windows Explorer, copy the UpdateManifest project from the {SamplesDir}\projects directory to the directory that contains the ExcelApplication solution.

  2. In Solution Explorer, right-click ExcelApplication.

  3. Point to Add on the shortcut menu, and then click Existing Project.

  4. Select the UpdateManifest project.

  5. Click OK.

  6. In Solution Explorer, right-click the UpdateManifest project, and then click Build.

  7. Add the primary output of the UpdateManifest project to the Setup project.

    This enables the Windows Installer file to run the custom action that edits the application manifest.

To add the primary output of the custom action project to the Setup project

  1. In Solution Explorer, right-click ExcelApplicationSetup.

  2. Point to View on the shortcut menu, and then click Custom Actions.

  3. In the Custom Actions editor, right-click the Custom Actions node, and then click Add Custom Action.

  4. In the Look In list, click Application Folder, and then click Add Output.

    The Add Project Output Group dialog box opens.

  5. In the Project list, click UpdateManifest.

  6. In the list of output types, select Primary output, and then click OK.

  7. Verify that Primary output from UpdateManifest (Active) is in the list of primary outputs for the Setup project, and then click OK.

  8. Add the required custom action data.

Bb332052.note(en-us,office.12).gifNote:
Although the custom action does not override the CommitRollback, and Uninstall methods, the base Windows Installer class provides an implementation. Thus, the methods must be called. However, they do not require any custom action data.

To add the custom action data for the Install method

  1. In the Custom Actions editor, expand Install.

  2. Right-click Primary output from UpdateManifest (Active), and then click Properties Window.

  3. In the Properties window, set the CustomActionData property to the following string. Enter this as one long string.

    /targetDir="[TARGETDIR]/" /documentName="ExcelApplication.xls" /assemblyName="ExcelApplication.dll"
    

Adding Launch Conditions to the .msi File

When the user runs Setup.exe, Windows Installer checks for the prerequisites and installs them if necessary. Alternatively, the user can double-click the .msi file to install the solution. In that case, the prerequisites are not installed and the solution cannot run. In other cases, Setup might fail because resources it needs are not present; for example, custom actions might require the .NET Framework.

This section shows you how to use the Launch Conditions editor to add launch conditions to the .msi file to prevent installation when certain dependencies are not installed.

To view the Launch Conditions editor

  1. In Solution Explorer, right-click ExcelApplicationSetup.

  2. Point to View on the shortcut menu, and then click Launch Conditions.

  3. Add a launch condition for the Visual Studio 2005 Tools for Office runtime.

To add a launch condition for the VSTO 2005 SE runtime

  1. In the Launch Conditions editor, right-click Requirements on Target Machine, and then click Add Registry Launch Condition.

  2. Select the newly added search condition, Search for RegistryEntry1.

  3. Rename the search condition to Search for VSTO 2005 SE Runtime.

  4. In the Properties window, change the value of Property to VSTORTVERSION.

  5. Also in the Properties window, set the value of RegKey to the following string:

    Software\Microsoft\vsto runtime Setup\v2.0.50727

  6. Leave the Root property set to vsdrrHKLM.

  7. Change the Value property to Update.

  8. Select the newly added launch condition, Condition1.

  9. Rename it to Display message if the Visual Studio 2005 Tools for Office SE Runtime is not installed.

  10. In the Properties window, change the value of the Condition property to the following:

    VSTORTVERSION >= "#3"

  11. Leave the InstallURL property blank.

  12. Change the value of the Message property to The Visual Studio 2005 Tools for Office SE Runtime is not installed. Please run Setup.exe.

If any users run your solutions with non–English settings for Windows, they must have the Visual Studio 2005 Tools for Office Language Pack to see runtime messages in the same language as Windows. Add a launch condition to check for the Language Pack.

To add a launch condition for the Visual Studio 2005 Tools for Office Language Pack

  1. In the Launch Conditions editor, right-click Requirements on Target Machine, and then click Add Windows Installer Launch Condition.

  2. Select the newly added search condition, Search for Component1.

  3. Rename the search condition to Search for VSTO Language Pack.

  4. In the Properties window, in the ComponentId property, type the following GUID:

    {2E3A394E-C9BD-40C3-9990-BA7AF7C8B4AF}

  5. Change the value of Property to COMPONENTEXISTS_VSTOLP.

  6. Select the newly added launch condition, (Condition1).

  7. Rename it to Display message if the Visual Studio 2005 Tools for Office Language Pack is not installed.

  8. In the Properties window, change the value of the Condition property to COMPONENTEXISTS_VSTOLP.

  9. Leave the InstallURL property blank.

  10. Change the value of the Message property to The Visual Studio 2005 Tools for Office Language Pack is not installed. Please run Setup.exe.

Testing the Installation

To test your Windows Installer, run it on a computer other than your development computer, because many of the prerequisites are already installed. Build your Setup project, and then run the Setup.exe file to test the bootstrapper.

To build the project

  • In Solution Explorer, right-click the ExcelApplicationSetup project, and then click Build.


  Reena Jain replied to Jipin M
12-Sep-11 02:25 AM
hi,

When you build the project, the code is compiled into an assembly that is included in the build output folder for the project. Visual Studio also creates a set of registry entries that enable Excel to discover and load the add-in, and it configures the security settings on the development computer to enable the add-in to run.

You will need to create a new Visual Studio project of type Excel 2007 Add-In (or Excel 2003 Add-In). The option for this can be found (in Visual Studio 2008) at:

New Project dialog -> Project types -> Visual C# -> Office

This Add-In will need to be installed on the target machine(s).

The Add-In will be able to hook into the Excel object model and therefore access any loaded spreadsheets etc.

The Add-In will also be able to add buttons to the Excel toolbar/ribbon.


for more detail check this
http://msdn.microsoft.com/en-us/library/cc668205.aspx
http://www.ferdychristant.com/blog//archive/DOMM-7DNHKN
http://www.clear-lines.com/blog/post/create-excel-2007-vsto-add-in-getting-started.aspx

Hope this will help you
Create New Account
help
Désinstaller microsoft office Office Sujet s?rement maintefois abord?s, donc d?sol? de remettre ?a. Je ne retrouve acheter un portable samsung R522. Je veux d?sinstaller le plus proprement possible la version office 2007 install? ? l'origine pour installer ma version 2000. Pour l'instant je ne l rant qu'un contributeur connaisse suffisamment ces programme pour m'indiquer lesquels d?sinstaller. - 2007 Microsoft office system - gestionnaire de contact professionnels pour Outlook 2007 sr1 - Microsoft office 2003 web Components - Microsoft office 2007 primary interop assemblies - Microsoft office live add-in 1
what use / connection are the following to MS Office 2007? Can i uninstall? Office Microsoft Office Small Business Connectivity Components Microsoft Office 2003 Web Components Microsoft Office 2007 Primary Interop Assemblies can i uninstall these safely if i am using Microsoft office
Setup MS Office SharePoint 2007 Test / Dev Environment Authentication Problems Hello all, i like to setup a fast mistake, but currently I am reading the logfiles placed under "c: \ program files \ common files \ microsoft shared \ web server extensions \ 12 \ logs". I don't find any relavant information regarding authentication EXE (0x0980) 0x0988 Windows SharePoint Services Database 880i High . . .tem.Data.SqlClient.SqlConnection.Open() bei Microsoft.SharePoint.Utilities.SqlSession.OpenConnection() 03 / 04 / 2010 13:53:11.35 OWSTIMER.EXE (0x0980) 0x0988 13:53:11.59 OWSTIMER.EXE (0x0980) 0x0988 Windows SharePoint Services Database 880k High bei Microsoft.SharePoint.Utilities.SqlSession.ExecuteReader(SqlCommand command, CommandBehavior behavior) bei Microsoft.SharePoint.Administration.SPConfigurationDatabase.FetchId(QualifiedObjectName qName) bei Microsoft.SharePoint.Administration.SPConfigurationDatabase.GetObject(String name, Guid parentId, Type type) bei Microsoft.SharePoint.Administration.SPConfigurationDatabase.get_Farm() bei Microsoft.SharePoint.Administration.SPFarm.FindLocal(SPFarm& farm, Boolean& isJoined) bei Microsoft.SharePoint.Administration.SPFarm.get_Local() bei
KB936677 keeps coming up Office I'm not at all sure what to do here. When I run windows update How do I stop this update from coming up? I've been to http: / / support.microsoft.com / kb / 936677 but my file versions are: OUTLFLTR.DAT 1.4.5007.1103 3 4.3504.0 300 KB (307, 440 bytes) I'm running Windows XP / sp2 and office 2003 / sp3 and searching around the web, there's other with the same problem :( Office Update Discussions SetARPINSTALLLOCATIONProperty (1) SetAVAILABLEFREEREGTerm (1) SetSMARTSOURCEDIR (1) WbBrwsrPckgRsrcDLLENUX86.3643236F (1) UnSetCONVERTTRIAL (1) DefUserAppDataOfflineFolder.E8D71C4B ABAEFB4C (1) Hi, allmixedup, I've seen a reference to enabling ose.exe: http: / / support.microsoft.com / ?id = 903774 That might help. Are you able to install other updates? Do you run this update? If not, you might need to contact Product Support. - - - - Susan Ramlet MVP - Office Please reply to the newsgroup. I cannot respond to private requests for help. Besides, then the community doesn't benefit from your question! I've just tried enabling the Office Source Engine and it's made no difference All other updates (except IE7, I choose not to install yet) have installed without a hitch, that's both Windows and Office. Even this (KB936677) update appears to have installed, giving the following message: 'The update was
Reference to: Microsoft.Office.Interop.Excel Office Hi, I am trying to include a using refernce to: "Microsoft.Office.Interop.Excel". I add the Microsoft Office 12 Library and a Microsoft.Office.core reference was added the project. But it did not have a reference to