Thomas Tingsted Mathiesen Visual Studio Office Tools SE, VSTO, Install
By Thomas Tingsted Mathiesen (tma@tma.dk)
Last changes made: 22 FEB 2007

  • Intro
    Did I have problems using the new Visual Studio Office Tools SE (VSTO), yes !
    The problem is not developing and using the VSTO library, but deploying it, and making it load.
    This walkthrough is showing you how to deploy an Outlook 2003 Add-in with VSTO.
    There is no way, that I know of, to do this in a simple One Click manner - you have to do these steps to make it work!.
    (Maby this will change when MS deploys a SP or an update to VSTO)

  • Essential downloads
    Visual Studio Office Tools (Microsoft Download)

  • Optional downloads
    Download VS2005 the project described below (757KB)

    Don't forget to rate/comment this page at the bottom

  • Create a new project
    Let's call our new add-in "MyAddin"



    Just add a Messagebox, to the ThisAddIn_Startup evenhandler, like so.


    Remove the Exclude check from all the referenced libraries.


    Rightclick on the MyAddin project, select Add refrence and select Microsoft.Office.Tools.Outlook


    Set the Copy Local to True


    Add a new Installer Class



    Click on Click here to switch to codeview



    It should look like this.



    Now copy the code below and insert it into your Installer Class.


    Click on the MyAddinSetup, and the button on top called Custom Actions Editor



    Rightclick on Install and select Add custom Action



    Open the Applications Folder and selct Primary output from MyAddin(Active)



    When you are done with this, it should look like this.



    RightClick on MyAddinSetup and select Rebuild.



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



    Once the Rebuild is complete, browse to your build folder.



    Execute Setup.exe



    Once the installation is complete, open your outlook, and this should happen.




    Print
    How would you rate the quality of this content?

    1 2 3 4 5 6 7 8 9
    Bad  Superb
    Rating   

    Give your feedback here.(Tags, links etc. not allowed!)

    Your Name:  (optional)
    Your homepage: http:// (optional)
     (Type the numbers)



    Date Name Rate Message Homepage
    15-09-2011Aldo Elam Majiah9
    Deploying vstor.exe (Visual Studio 2005 Tools for Office Second Edition Runtime) using Group Policy.
    1. Copy vstor.exe to a share folder. Give the share folder read access to Domain Users
    2. Create a GPO and apply it to appropiate Computers Organizational Unit (not Users OU).
    3. In the OU, modify startup script (Computer Configuration -- Windows Settings -- Scripts -- Startup.
    4. Make your GPO run the script below. Give a .vbs extension to the script (Its a vbscript). You might want to encrypt it into a .vbe file because the

    script contains a password.

    this GPO and script have been tested succesfully.


    ------------------------
    Option explicit
    Dim oShell
    Dim objFSO, strSourceFile, strTargetFile

    strSourceFile = \servernameshare_foldervstor.exe
    strTargetFile = c:

    set oShell= Wscript.CreateObject(WScript.Shell)
    Set objFSO = CreateObject(Scripting.FileSystemObject)

    On Error Resume Next
    If objFSO.FileExists( strTargetFile) Then
    Endend
    Else
    objFSO.CopyFile strSourceFile, strTargetFile
    End If

    oShell.Run RunAs /noprofile /user:your_domainadministrative_account C:vstor.exe /q
    WScript.Sleep 100
    oShell.Sendkeys password_of_the_administrative_account~

    Endend:
    Wscript.Quit
    ---------------------------


    Regards,
    Aldo Elam Majiah
     
    29-07-2011Oliver8Great description, thanks! 
    30-06-2010Nathan8Great, but:

    if (!machinePolicyLevel.RootCodeGroup.Children.Contains(codeGroup))
    {
    machinePolicyLevel.RootCodeGroup.AddChild(codeGroup)
    }

    for several installations, works more elegantly...
    (Sorry for my english)
    n-soft.pl
    28-05-2010sopan9Thanks Dear
    This article is very useful
     
    01-03-20109Great article and thanks a lot. 
    22-01-20109Thanks a lot, it works 
    14-09-2009Shreez9Thanks a ton!!! it helped me a lot.www.whattoname.com
    27-08-20099Great work! Heres the c# version of the code.

    public override void Install(IDictionary stateSaver)
    {
    base.Install(stateSaver)

    try
    {
    PolicyLevel machinePolicyLevel = null
    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.)

    PermissionSet permissionSet = new NamedPermissionSet(FullTrust)
    string assemblyPath = this.Context.Parameters[assemblypath]
    string installDirectory = assemblyPath.Substring(0, assemblyPath.LastIndexOf(\))
    if (!installDirectory.EndsWith(\))
    installDirectory = installDirectory + \
    installDirectory +=
    installDirectory += *

    IMembershipCondition membershipCondition = new UrlMembershipCondition(installDirectory)
    PolicyStatement policyStatement = new PolicyStatement(permissionSet)
    CodeGroup codeGroup = new UnionCodeGroup(membershipCondition, policyStatement)
    codeGroup.Description = VSTO Permissions for Objectware AS Plugins
    codeGroup.Name = Objectware AS
    machinePolicyLevel.RootCodeGroup.AddChild(codeGroup)
    SecurityManager.SavePolicy()
    }
    catch (Exception ex)
    {
    MessageBox.Show(Ex1: + ex.ToString(), Installer error)
    }
    }
     
    13-07-20099 
    20-04-20098Thanks for this sample and it works great. I am trying to add a new project in C# for Ms Excel 2003 with VS.NET 2005. When I deploy it does not work at all - I have no idea why as everything is the same as outlook!

    Could anyone advise?

    Regards,

    LG
     
    26-01-20099 
    16-09-2008YUDS8Good Article 
    11-07-20089 
    01-02-2008SAURABH4BUT IT NOT WORKS WHEN I RUN SETUP ON CLIENT MACHINE 
    29-01-20087Understanding what is done is not required to port this VB.NET into C#.NET.
    Actually, namespaces, methods naming... are the same in the both language. They just differ from syntax.
    As argument I do not know VB.NET but I made the translation for about 5 minutes...

    But as Dsnyder have noticed about the line containing:

    Dim assemblyPath As String = Me.Context.Parameters(assemblypath)

    that does not compile. So, some changes have to be done.
    Actually we can replace the line below by the following lines. Lets see:

    System.Collections.IEnumerator parameters = Context.Parameters.GetEnumerator()
    String assemblyPath = null
    while (parameters.MoveNext())
    {
    System.Collections.DictionaryEntry entry = (System.Collections.DictionaryEntry)parameters.Current
    if (assemblypath.Equals((String)entry.Key))
    assemblyPath = (String)entry.Value
    }

    if (assemblyPath == null)
    {
    throw new ApplicationException(Could not find assembly path)
    }

    It surely can be simplier than that you have seen. But it works fine.



    Thank you very much for this input :)

    /Thomas

     
    22-01-2008Dsnyder9Srivinas, Im guessing you used a code converter that didnt properly change the brackets. if you change this:
    string assemblyPath = this.Context.Parameters(assemblypath)

    to this:
    string assemblyPath = this.Context.Parameters[assemblypath]

    it should compile just fine.
     
    21-01-2008Srinivas8its a nice article. can u tell me in the installer class iam getting one error that is...[i have developed this in c#]

    Dim assemblyPath As String = Me.Context.Parameters(assemblypath) in c# it is..

    string assemblyPath = this.Context.Parameters(assemblypath)


    for this iam getting the error as.....
    Error 1 System.Configuration.Install.InstallContext.Parameters is a property but is used like a method E:NewaddinNewaddinInstaller1.cs 34 49 Newaddin
    srinivas.rejeti@nannacomputers.com
    18-01-2008MBurger9Great article, thanks a lot! I notice there is more (needed) code in the installer1.vb found in the zipped file than whats explained here. 
    12-12-2007Nick Lucas9Its a bit easier with Office 2007, you dont need to copy the Outlook.dll. If anyone wants the installer code in c# mail me nickl at pinewood dot co dot uk 
    23-11-2007jainishcs9it is nicejainishcs@yahoo.com
    19-11-20079Great work, its a slap on MSDN 
    25-10-2007Bhavesh Jain9BEST BEST BEST deployment article. I couldn`t get through this issue since last 4 weeks, this article helped get through issue in just few mins.. Cheers!!! 
    26-09-2007GL9Thanks a million for this article...MSDNs walkthroughs on this were horrible. 
    19-09-2007djm9thnks great 
    10-09-20079 
    31-08-20079 
    30-07-20079 
    27-06-2007oh9Super artikel. Mange tak for hjælpen

     
    08-06-2007vipul9Its really gr8 article, thanks lot buddy