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.
- Open Visual Studio 2010 and open the starter solution at %Office2010DeveloperTrainingKitPath%\Labs\Deployment\Source\[language]\Starter\ClickOnceDeployment\ClickOnceDeployment.sln
- Create the post deployment action class
- Right click the WordAddIn project in the Solution Explorer and click Add -> New Item
- Select a type of class and name it FileDeploymentAction.cs(FileDeploymentAction.vb in case of VB)
Add the following using statements to the new class file
using System.IO; using Microsoft.VisualStudio.Tools.Applications.Deployment;
Imports System.IO Imports Microsoft.VisualStudio.Tools.Applications.Deployment
Update the class to implement the IAddInPostDeploymentAction interface using the code below
public class FileDeploymentAction : IAddInPostDeploymentAction { }
Public Class FileDeploymentAction Implements IAddInPostDeploymentAction End Class
- Implement the Execute method of the IAddinPostDeployment interface.
- Create a new file at C:\AddInFile.txt and write Hello World to the file.
public void Execute(AddInPostDeploymentActionArgs args) { using (StreamWriter writer = File.CreateText(@“C:\AddInFile.txt”)) writer.WriteLine(“Hello World”); }
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.
- Publish version 3.0.0.0 of the WordAddIn using the project Properties page
- Right click the WordAddIn project in the Solution Explorer and click Properties
- In the Publish tab, verify the version is 3.0.0.0. If not change it to 3.0.0.0
- Click Publish to create the ClickOnce deployment files.
- Update the ClickOnce manifest file to include the postActions section that identifies the assembly and class containing the post deployment action.
- In WindowsExplorer navigate to \\demo2010a\AddInDeploy\WordAddIn\Application Files\WordAddIn_3_0_0_0
- Open the WordAddIn.dll.manifest file in Visual Studio 2010
Immediately following the vstav3:update element add the following markup to define the post deployment action.
<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>
- Save the changes and close the file
- Re-sign the manifests using mage.exe and the key file for the add-in
- Open the Visual Studio Command Prompt (2010) by Programs -> Microsoft Visual Studio 2010 -> Visual Studio Tools
- Change the directory to C:\AddInDeploy\WordAddIn
Use mage.exe to re-sign the WordAddIn.dll.manifest file (adjust path accordingly)
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”
- Use mage.exe to re-sign the WordAddIn.vsto file (adjust path accordingly)
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.
- In Windows Explorer navigate to \\demo2010a\AddInDeploy\WordAddIn and double click WordAddIn.vsto to install the add-in
- Navigate to C:\ in Windows Explorer and verify the AddInFile.txt exists and contains Hello World