Monday, October 12, 2009

Deploying VSTO

This is in reference to my previous post on Adding Outlook Pane using VSTO

Deploying a VSTO addin is not straight forward even though Microsoft Visual Studio 2005 adds a deployment setup project into the solution with the required dependecies. I am writing this page refering to Mathiesen's Post on Deployment in VSTO in VB.Net  Here i am going to explain the same in C# just in 10 steps.


You can download the project from the link at the end of this post

1) Add a Reference to Microsoft.Office.Tools.Outlook

Add Refernce


2) Now Right click on Outlook assembly in the References folder and Set Copy Local to TRUE


3) Now in the deployment project Include all the excluded dependencies by visual studio. Right Click on the excluded ones and uncheck the Exclude as shown below.


4) Add a Installer Class to your Outlook Panel Project.

5) Once you add the Installer Class, Switch to Code view of Installer1 class. Copy the method posted below and add it into the Installer1.cs. This grants full permission on the assembly.

//Add these NameSpaces
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.Security;
using System.Security.Policy;

//Add this method
 public override void Install(System.Collections.IDictionary stateSaver)
        {
            base.Install(stateSaver);

            try
            {               
                // Find the machine policy level

                PolicyLevel machinePolicyLevel = null;

                System.Collections.IEnumerator policyHierarchy = SecurityManager.PolicyHierarchy();

                while (policyHierarchy.MoveNext())
                {
                    PolicyLevel level = (PolicyLevel)policyHierarchy.Current;

                    if (level.Label == "Machine")
                    {
                        machinePolicyLevel = level;

                        break;
                    }
                }

                if (machinePolicyLevel == null)
                {
                    throw new ApplicationException(
                        "Could not find Machine Policy level. Code Access Security " +

                        "is not configured for this application."
                        );
                }

                // Create a new FullTrust permission set
                PermissionSet permissionSet = new NamedPermissionSet("FullTrust");

                // Get the install directory of the current installer

                string assemblyPath = this.Context.Parameters["assemblypath"];

                string installDirectory = assemblyPath.Substring(0, assemblyPath.LastIndexOf("\\"));


                if (!installDirectory.EndsWith(@"\"))
                    installDirectory += @"\";

                installDirectory += "*";

                IMembershipCondition membershipCondition =

                    new UrlMembershipCondition(installDirectory);


                // Create the code group

                PolicyStatement policyStatement = new PolicyStatement(permissionSet);

                CodeGroup codeGroup = new UnionCodeGroup(membershipCondition, policyStatement);

                codeGroup.Description = "VSTO Permissions for Objectware AS Plugins";

                codeGroup.Name = "Objectware AS";

                // Add the code group

                machinePolicyLevel.RootCodeGroup.AddChild(codeGroup);

                // Save changes

                SecurityManager.SavePolicy();

            }
            catch (Exception ex)
            {
                System.Windows.Forms.MessageBox.Show(ex.ToString());
            }
        }

6) Now, Right click on your Setup/Deployment project ( Outlook PanelSetup in this Case)  and View Custom Actions.



7) Now Right Click on Install and Add Custom Actions. Double Click on the Application Folder.

8) Select Add Primary Output from Outlook Panel 


9)Add your Company name, Support URL, Manufacturer or any other support information into the setup. Select the Deployment project  and press F4 to bring up the properties window (Not by Right Click - Properties)
 


10) Now Build Outlook Panel project and Rebuild the Setup project also.


Locate the Executable files on the Project Setup folder.



If you are installing the Addin on a different machine, remember to install Visual Studio 2005 Tools for Office Second Edition before installing your Addin. The installation file is vstor.exe and it usually resides in your C:\Program Files\Microsoft Visual Studio 8\Visual Studio 2005 Tools for Office Second Edition folder. 

NOTE:
1) Installing on a Vista or Windows 7 needs bit modification to the same. You can read the same in VSTO Add-In and Vista
2) You can download the above mentioned example project in Outlook Panel using VSTO 
Please Don't forget to comment this page at the bottom 

3 comments:

Ramz Monday, 21 December, 2009  

I implemented the same for my project. Thanks dude!!

Anonymous,  Thursday, 04 February, 2010  

Great walkthrough! I have been looking for 3 days for an explanation of how to deploy a VSTO add-in and this is not only simpler than most, it actually works!

Anonymous,  Monday, 22 March, 2010  

Hi,

Nice article. It helped me !!

I want to send my Custom Form as e-mail in outlook.
Say i submit a from & it goes to my superior for Approval - now i want that when my superior clicks on the notification e-mail, the Approval form should directly be opened.

Can you help me in this ?

Popular Posts

Blog Archive

About Us

Share this Page

  © Internet Blues

Back to TOP