Exercise 2: Post Deployment Actions

In this exercise you will be adding a post deployment assembly to a project and use it to deploy a data file along with the add-in. This will require manual updates to be made to the deployment manifest and consequently a manual re-signing of the manifest using mage.exe.

Task 1 – Create the post deployment action

In this task, you will create the class that will contain the code to execute once deployment of the add-in has completed.

  1. Open Visual Studio 2010 and open the starter solution at %Office2010DeveloperTrainingKitPath%\Labs\Deployment\Source\[language]\Starter\ClickOnceDeployment\ClickOnceDeployment.sln
  2. Create the post deployment action class
    1. Right click the WordAddIn project in the Solution Explorer and click Add -> New Item
    2. Select a type of class and name it FileDeploymentAction.cs(FileDeploymentAction.vb in case of VB)
    3. Add the following using statements to the new class file

      C#

      using System.IO; using Microsoft.VisualStudio.Tools.Applications.Deployment;

      Visual Basic

      Imports System.IO Imports Microsoft.VisualStudio.Tools.Applications.Deployment

    4. Update the class to implement the IAddInPostDeploymentAction interface using the code below

      C#

      public class FileDeploymentAction : IAddInPostDeploymentAction { }

      Visual Basic

      Public Class FileDeploymentAction Implements IAddInPostDeploymentAction End Class

  3. Implement the Execute method of the IAddinPostDeployment interface.
    1. Create a new file at C:\AddInFile.txt and write Hello World to the file.

      C#

      public void Execute(AddInPostDeploymentActionArgs args) { using (StreamWriter writer = File.CreateText(@“C:\AddInFile.txt”)) writer.WriteLine(“Hello World”); }

      Visual Basic

      Public Sub Execute(ByVal args As AddInPostDeploymentActionArgs) Using writer As StreamWriter = File.CreateText("C:\AddInFile.txt") writer.WriteLine("Hello World") End Using End Sub

Task 2 – Update the deployment’s manifest files and re-sign them

In this task, you will update the manifest file for the addin and then re-sign it to update the signatures on the file.

  1. Publish version 3.0.0.0 of the WordAddIn using the project Properties page
    1. Right click the WordAddIn project in the Solution Explorer and click Properties
    2. In the Publish tab, verify the version is 3.0.0.0. If not change it to 3.0.0.0
    3. Click Publish to create the ClickOnce deployment files.
  2. Update the ClickOnce manifest file to include the postActions section that identifies the assembly and class containing the post deployment action.
    1. In WindowsExplorer navigate to \\demo2010a\AddInDeploy\WordAddIn\Application Files\WordAddIn_3_0_0_0
    2. Open the WordAddIn.dll.manifest file in Visual Studio 2010
    3. Immediately following the vstav3:update element add the following markup to define the post deployment action.

      XML

      <vstav3:postActions> <vstav3:postAction> <vstav3:entryPoint class="WordAddIn.FileDeploymentAction"> <assemblyIdentity name="WordAddIn" version="1.0.0.0" language="neutral" processorArchitecture="msil" /> </vstav3:entryPoint> <vstav3:postActionData></vstav3:postActionData> </vstav3:postAction> </vstav3:postActions>

    4. Save the changes and close the file
  3. Re-sign the manifests using mage.exe and the key file for the add-in
    1. Open the Visual Studio Command Prompt (2010) by Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools
    2. Change the directory to C:\AddInDeploy\WordAddIn
    3. Use mage.exe to re-sign the WordAddIn.dll.manifest file (adjust path accordingly)

      CMD

      mage -Sign "Application Files\WordAddIn_3_0_0_0\WordAddIn.dll.manifest" -CertFile "C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\ ClickOnceDeployment\WordAddIn\WordAddIn_TemporaryKey.pfx”

    4. Use mage.exe to re-sign the WordAddIn.vsto file (adjust path accordingly)

      CMD

      mage -Update "WordAddIn.vsto" -AppManifest "Application files\WordAddIn_3_0_0_0\WordAddIn.dll.manifest" -CertFile "C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\ ClickOnceDeployment\WordAddIn\WordAddIn_TemporaryKey.pfx"

Task 3 – Test the post deployment action

In this task, you will configure the existing Add-in for publishing.

  1. In Windows Explorer navigate to \\demo2010a\AddInDeploy\WordAddIn and double click WordAddIn.vsto to install the add-in
  2. Navigate to C:\ in Windows Explorer and verify the AddInFile.txt exists and contains Hello World