22
Hands-On Lab Security and Deployment Lab version: 1.0.0 Last updated: 2/23/2011

Security and Deployment Lab

  • Upload
    others

  • View
    15

  • Download
    0

Embed Size (px)

Citation preview

Page 1: Security and Deployment Lab

Hands-On Lab

Security and Deployment

Lab version: 1.0.0

Last updated: 2/23/2011

Page 2: Security and Deployment Lab

CONTENTS

OVERVIEW ................................................................................................................................................... 3 Starting Materials 4

EXERCISE 1: TRUST AND DEPLOYMENT WITH OFFICE ADD-INS ....................................................... 4 Task 1 – Configure the Add-in for publishing ........................................................................................ 4

Task 2 – Trusting the AddIn Installation................................................................................................ 5

Task 3 – Upgrading the Add-in .............................................................................................................. 6

Task 4 – Verify the upgrade works automatically ................................................................................. 6

EXERCISE 2: POST DEPLOYMENT ACTIONS.......................................................................................... 7 Task 1 – Create the post deployment action ........................................................................................ 8

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

Task 3 – Test the post deployment action .......................................................................................... 10

EXERCISE 3: MULTIPLE ADD-IN DEPLOYMENTS ................................................................................ 10 Task 1 – Combine both add-in files into a single folder ...................................................................... 11

Task 2 – Create a single combined manifest file for the addin ........................................................... 11

Task 3 – Re-sign the manifest files ...................................................................................................... 14

Task 4 – Test the multi add-in deployment ........................................................................................ 14

EXERCISE 4: DEPLOYING DOCUMENT TEMPLATES IN A WSP ......................................................... 15 Task 1 – Create a new SharePoint 2010 project ................................................................................. 15

Task 2 – Create the SharePoint objects needed to deploy the Invoice Document ............................ 15

Task 3 – Create the Feature that will deploy the InvoiceDocument Add-in ....................................... 18

Task 4 – Deploy and test the new Invoice Document template ......................................................... 20

SUMMARY .................................................................................................................................................. 21

APPENDIX .................................................................................................................................................. 22 No Items 22

Page 3: Security and Deployment Lab

Overview

In this lab exercise, you will use the VSTO Runtime 2010 to deploy several add-ins. The deployment

scenarios used will represent real world scenarios that require secure deployment of multiple add-ins

via SharePoint.

Objectives

In this lab you will:

Learn how to deploy Office Add-ins using ClickOnce Deployment

Learn how to use post deployment actions

Learn to create deployments containing multiple addins

Learn how to create a WSP file to deploy an Office Document template

System Requirements

This lab assumes that you have SharePoint Server installed in a test environment. For guidance on how

to setup SharePoint Server see http://msdn.microsoft.com/en-us/library/ee554869(office.14).aspx.

Note that any URL referred to in this lab must be adjusted for use with your local setup. You must have

the following items to complete this lab:

Microsoft® Windows® Vista SP1 or Microsoft® Windows Server 2008 (64-bit)

Microsoft® SharePoint Server 2010 (64-bit)

Microsoft® Office Professional Plus 2010 (32-bit or 64-bit)

Microsoft® Visual Studio 2010

Setup

You must perform the following steps to prepare your computer for this lab. This consists primarily of

creating a SharePoint site collection at http://intranet.contoso.com/sites/Deployment and installing

the code snippets for this lab.

1. Run the command file Setup.bat located at

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\.

Page 4: Security and Deployment Lab

Exercises

This Hands-On Lab is comprised of the following exercises:

1. Trust and Deployment with Office Add-ins

2. Post Deployment Actions

3. Multiple Add-in Deployments

4. Deploying Document Templates in a WSP

Estimated time to complete this lab: 60 minutes.

Starting Materials

This Hands-On Lab includes the following starting materials.

Visual Studio solutions. The lab provides the following Visual Studio solutions that you can use

as starting point for the exercises. The lab instructions assume that you installed the training kit

to the default location, C:\Office2010DeveloperTrainingKit\.

◦ C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\Clic

kOnceDeployment\ClickOnceDeployment.sln: Use the existing addins to perform

upgrades, create post deployment actions, and multi add-in deployments.

◦ C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\Solu

tionDeployment\SolutionDeployment.sln: Deploy the existing add-in using a

SharePoint application packaged as a WSP.

Note: Inside the lab’s Source folder, you will find a Solution folder containing an end solution

with the completed lab exercise.

Exercise 1: Trust and Deployment with

Office Add-ins

In this exercise you will create a simple Office add-in that utilizes ClickOnce deployment. You will learn

how to perform secure ClickOnce deployment by registering certificates and securely manage automatic

updates to the add-in.

Task 1 – Configure the Add-in for publishing

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

Page 5: Security and Deployment Lab

1. Open Visual Studio 2010 and open the starter solution at

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\ClickOnceD

eployment\ClickOnceDeployment.sln

2. Locate the WordAddIn project in the Solution Explorer and open the project’s properties by

right clicking the project and selecting Properties.

3. Configure the project to publish to the \\demo2010a\AddinDeploy\WordAddIn folder with

updates enabled

a. In the properties window select the Publish tab

b. Change the Publishing folder to \\demo2010a\AddinDeploy\WordAddIn

c. Click the Updates button and choose the Check every time the customization runs

option

d. Close the update dialog by clicking OK

e. Verify the publish version is 1.0.0.0

f. Uncheck the Automatically increment revision with each release check box

g. Click Publish Now button to create the ClickOnce installation

Task 2 – Trusting the AddIn Installation

In this task, you will install the add-in and setup the appropriate certificates to fully trust the add-in.

1. Open \\demo2010a\AddinDeploy\WordAddIn and install the addin

a. Open Windows Explorer and navigate to \\demo2010a\AddinDeploy\WordAddIn

b. Double click WordAddIn.vsto in the WordAddIn folder to start the installation

c. Wait for the warning dialog that asks if you want to install the addin

d. Click the More Information button to see the details of why you are warned and

then click Close and Don’t Install

2. Add the certificates used to sign the add-in to the appropriate certificate stores

a. Run a new Visual Studio Command Prompt (2010) in Programs -> Microsoft Visual

Studio 2010 -> Visual Studio Tools

b. Change the directory to

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\

ClickOnceDeployment\WordAddIn

c. Execute the following commands to register the certificates

CMD

certmgr –add –c WordAddIn_TemporaryKey.pfx –s Root

certmgr –add –c WordAddIn_TemporaryKey.pfx –s TrustedPublisher

Page 6: Security and Deployment Lab

Note: If you copy and paste the above script, make sure to retype the - characters

3. Open \\demo2010a\AddinDeploy\WordAddIn and install the addin

a. Open Windows Explorer and navigate to \\demo2010a\AddinDeploy\WordAddIn

b. Double click WordAddIn.vsto in the WordAddIn folder to start the installation

Note: The add-in should install with no user interaction required.

4. Verify the add-in installed by running Office Word 2010

a. Start Office Word 2010

b. Verify a dialog is shown indicating that Version 1 of the add-in is installed

Task 3 – Upgrading the Add-in

In this task, you will allow Office to automatically upgrade the add-in by publishing a new version.

1. Upgrade the addin to version 2

a. Switch back to Visual Studio 2010

b. Locate ThisAddIn.cs(ThisAddIn.vb in case of VB) in the Solution Explorer, right click

it and select View Code

c. Update the MessageBox.Show call to display Version 2 instead of Version 1

2. Publish a version 2.0.0.0 of the addin to the \\demo2010a\AddInDeploy\WordAddIn folder

a. Open the project’s properties by right clicking the project in the Solution Explorer

and clicking Properties

b. In the properties window, select the Publish tab

c. Change the publish version to 2.0.0.0

d. Click Publish Now button to create the updated ClickOnce installation

Note: This does not overwrite the existing version 1.0 addin. It creates a second add-

in in a new folder, but it does overwrite the .vsto file to redirect installation to the new

version.

Task 4 – Verify the upgrade works automatically

In this task, you will uninstall all versions of the add-in and reinstall them watching the automatic

upgrade work.

Page 7: Security and Deployment Lab

Note: Rebuilding the addins creates registry entries that will interfere with the testing of the

automatic upgrade of addins. To eliminate these problems, you will need to clean the WordAddIn

project and install all previous versions of the addin.

1. Clean the WordAddIn project by right clicking it in the Solution Explorer and clicking Clean

2. Uninstall all previous versions of the addin using the Uninstall a program link in Control

Panel

a. Open the Control Panel using the Start Menu

b. Click Uninstall a program to load the list of installed applications

c. Locate WordAddIn and click Uninstall

3. Manually revert the version of the addin back to 1.0.0.0 and install it

a. In Windows Explorer open \\demo2010a\AddInDeploy\WordAddIn

b. Copy the .vsto file from the ApplicationFiles\WordAddIn_1_0_0_0 folder to the

WordAddIn folder

c. Double click the .vsto file in the WordAddIn folder to install the add-in

4. Verify the add in version 1.0.0.0 is installed

a. Start Office Word 2010

b. Verify a dialog is shown indicating that Version 1 of the add-in is installed

5. Manually update the version of the addin to 2.0.0.0

a. In Windows Explorer open \\demo2010a\AddInDeploy\WordAddIn

b. Copy the .vsto file from the ApplicationFiles\WordAddIn_2_0_0_0 folder to the

WordAddIn folder

6. Test the automatic update by running Word 2010 and verifying the updated version is

installed

a. Start Office Word 2010

b. Verify a dialog is shown indicating that Version 2 of the add-in is installed

Note: When word is started it should check and automatically install the new version

of the add-in

Exercise 2: Post Deployment Actions

Page 8: Security and Deployment Lab

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

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\ClickOnceD

eployment\ClickOnceDeployment.sln

2. Create the post deployment action class

a. Right click the WordAddIn project in the Solution Explorer and click Add -> New

Item

b. Select a type of class and name it

FileDeploymentAction.cs(FileDeploymentAction.vb in case of VB)

c. 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

d. 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.

a. Create a new file at C:\AddInFile.txt and write Hello World to the file.

Page 9: Security and Deployment Lab

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

a. Right click the WordAddIn project in the Solution Explorer and click Properties

b. In the Publish tab, verify the version is 3.0.0.0. If not change it to 3.0.0.0

c. 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.

a. In Windows Explorer navigate to

\\demo2010a\AddInDeploy\WordAddIn\Application Files\WordAddIn_3_0_0_0

b. Open the WordAddIn.dll.manifest file in Visual Studio 2010

c. 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>

Page 10: Security and Deployment Lab

d. Save the changes and close the file

3. Re-sign the manifests using mage.exe and the key file for the add-in

a. Open the Visual Studio Command Prompt (2010) by Programs -> Microsoft Visual

Studio 2010 -> Visual Studio Tools

b. Change the directory to C:\AddInDeploy\WordAddIn

c. 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]\Sta

rter\

ClickOnceDeployment\WordAddIn\WordAddIn_TemporaryKey.pfx”

d. 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]\Sta

rter\

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

Exercise 3: Multiple Add-in Deployments

In this exercise you will be taking two addins and deploying them using the same ClickOnce deployment.

This will require manual updates to be made to the deployment manifest and consequently a manual re-

signing of the manifest using mage.exe.

Page 11: Security and Deployment Lab

Task 1 – Combine both add-in files into a single folder

In this task, you will publish two separate add-ins and compile their published files into a single folder.

1. Open Visual Studio 2010 and open the starter solution at

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\ClickOnc

eDeployment\ClickOnceDeployment.sln

2. Publish both the WordAddIn and ExcelAddIn projects

a. Right click the WordAddIn in the Solution Explorer and click Properties

b. In the Publish tab, verify the version is set to 4.0.0.0. If not change it to 4.0.0.0

c. Click Publish to create the ClickOnce deployment

d. Repeat the previous steps for the ExcelAddIn project

3. Create a new MultiAddIn folder in the C:\AddInDeploy folder and copy both addins into it

a. In Windows Explorer navigate to the C:\AddInDeploy folder

b. Create a new folder named MultiAddin

c. Copy all files in ExcelAddIn into the new MultiAddIn folder

d. Rename the MultiAddIn\Application Files\ExcelAddIn_4_0_0_0 to

MultiAddIn_4_0_0_0.

e. Copy all the files in WordAddIn\Application Files\WordAddIn_4_0_0_0 into

MultiAddIn\Appliction Files\MultiAddIn_4_0_0_0

Task 2 – Create a single combined manifest file for the addin

In this task, you combine the contents of each add-ins manifest file into a single manifest file.

1. Combine the dependent assemblies in each addin into a single manifest file

a. In Windows Explorer navigate to C:\AddInDeploy\MultiAddIn

b. Rename the ExcelAddIn.vsto file to MultiAddin.vsto

c. Navigate to C:\AddInDeploy\MultiAddIn\Application Files\MultiAddIn_4_0_0_0

d. Delete the WordAddIn.vsto and ExcelAddIn.vsto files

e. Rename WordAddIn.dll.manifest to MultiAddIn.manifest

f. Open MultiAddIn.manifest in Visual Studio 2010

g. Locate the description element at the top of the file and change the text to

MultiAddIn – Multiple AddIn ClickOnce Deployment

2. Combine the contents of the ExcelAddIn.dll.manifest with the new MultiAddIn.manifest

a. Open ExcelAddIn.dll.manifest in Visual Studio 2010

Page 12: Security and Deployment Lab

b. Locate the following dependencies and copy them into the MultiAddIn.manifest file

immediately following the existing dependency elements

Note: DO NOT copy the markup below. The hash token will not match your

assemblies.

XML

<dependency>

<dependentAssembly dependencyType="preRequisite"

allowDelayedBinding="true">

<assemblyIdentity name="Microsoft.Office.Interop.Excel"

version="14.0.0.0"

publicKeyToken="71E9BCE111E9429C"

language="neutral"

processorArchitecture="msil" />

</dependentAssembly>

</dependency>

<dependency>

<dependentAssembly dependencyType="preRequisite"

allowDelayedBinding="true">

<assemblyIdentity name="Microsoft.Office.Tools.Excel.v9.0"

version="9.0.0.0"

publicKeyToken="B03F5F7F11D50A3A"

language="neutral"

processorArchitecture="msil" />

</dependentAssembly>

</dependency>

<dependency>

<dependentAssembly dependencyType="install"

allowDelayedBinding="true"

codebase="ExcelAddIn.dll" size="11776">

<assemblyIdentity name="ExcelAddIn"

version="1.0.0.0" language="neutral"

processorArchitecture="msil" />

<hash>

<dsig:Transforms>

<dsig:Transform Algorithm="urn:schemas-microsoft-

com:HashTransforms.Identity" />

</dsig:Transforms>

<dsig:DigestMethod Algorithm="http://www.w3.org/

2000/09/xmldsig#sha1" />

<dsig:DigestValue>ho2Y/Ad8HU2Lc5YAFs9UFt2/N58=</dsig:DigestValue>

</hash>

</dependentAssembly>

</dependency>

Page 13: Security and Deployment Lab

3. Update the addin section to indicate that two add-ins are contained in the deployment

a. Locate the vstav3:addIn/vstav3:entryPointsCollection element

b. Add an id attribute with a value of Word to the vstav3:entryPoints element

XML

<vstav3:entryPoints id="Word">

<vstav3:entryPoint class="WordAddIn.ThisAddIn">

<assemblyIdentity name="WordAddIn" version="1.0.0.0"

language="neutral" processorArchitecture="msil" />

</vstav3:entryPoint>

</vstav3:entryPoints>

c. Add a second vstav3:entryPoints element to include the Excel addin

XML

<vstav3:entryPoints id="Excel">

<vstav3:entryPoint class="ExcelAddIn.ThisAddIn">

<assemblyIdentity name="ExcelAddIn" version="1.0.0.0"

language="neutral" processorArchitecture="msil" />

</vstav3:entryPoint>

</vstav3:entryPoints>

d. Locate the vstov4:customizations element and add an id attribute with a value of

Word to the vstov4:customization element

XML

<vstov4:customization id="Word">

<vstov4:appAddIn application="Word" loadBehavior="3"

keyName="WordAddIn">

<vstov4:friendlyName>WordAddIn</vstov4:friendlyName>

<vstov4:description>WordAddIn</vstov4:description>

</vstov4:appAddIn>

</vstov4:customization>>

e. Add a second vstov4:customization element to include the Excel addin.

XML

<vstov4:customization id="Excel">

<vstov4:appAddIn application="Excel" loadBehavior="3"

keyName="ExcelAddIn">

<vstov4:friendlyName>ExcelAddIn</vstov4:friendlyName>

<vstov4:description>ExcelAddIn - Excel add-in</vstov4:description>

</vstov4:appAddIn>

</vstov4:customization>

Page 14: Security and Deployment Lab

Task 3 – Re-sign the manifest files

In this task, you will re-sign the manifest files. This is necessary due to the changes made in previous

tasks. If the files are not re-signed, the VSTO Runtime 2010 will treat the files as if they are corrupted.

1. Open the Visual Studio Command Prompt (2010) and change directory to

C:\AddInDeploy\MultiAddIn.

2. Re-sign the manifest files using the key generated by the WordAddIn project.

a. Open the Visual Studio Command Prompt (2010)

b. Change directory to C:\AddInDeploy\MultiAddIn

c. Use mage.exe to re-sign the application manifest file

CMD

mage.exe

-Sign "Application Files\MultiAddIn_4_0_0_0\MultiAddIn.dll.manifest"

-CertFile "C:\Office2010DeveloperTrainingKit\Labs\Deployment\Starter\

ClickOnceDeployment\WordAddIn\WordAddIn_TemporaryKey.pfx"

d. Use mage.exe to re-sign the deployment manifest file

CMD

mage.exe

-Update "MultiAddIn.vsto"

-AppManifest "Application files\MultiAddIn_4_0_0_0\

MultiAddIn.manifest"

-CertFile "C:\Office2010DeveloperTrainingKit\Labs\Deployment\Starter\

ClickOnceDeployment\WordAddIn\WordAddIn_TemporaryKey.pfx"

Task 4 – Test the multi add-in deployment

In this task, you will install the single MultiAddIn ClickOnce Deployment and verify that both the

WordAddIn and ExcelAddIn are installed.

1. Verify no previous versions of the AddIns are deployed

a. Click Uninstall a program in the Control Panel

b. Uninstall and previous versions of ExcellAddIn or WordAddIn

2. Install the MultiAddIn ClickOnce deployment package.

a. Navigate to \\demo2010a\AddInDeploy\MultiAddIn in Windows Explorer

b. Double click MultiAddIn.vsto to install the add-in

c. Run Word 2010 and verify the add-in installed correctly

Page 15: Security and Deployment Lab

d. Run Excel 2010 and verify the add-in installed correctly

Exercise 4: Deploying Document

Templates in a WSP

In this exercise you will be taking an add-in and a document template that have already been created

and deploying them in a WSP. You’ll learn how to add a simple add-in to a Module element and deploy

it to a SharePoint Server. Then you’ll learn how to deploy a document template to a new Document

Library and update its deploy location using a feature receiver.

Task 1 – Create a new SharePoint 2010 project

In this task, you will publish the InvoiceTemplate add-in and create a new SharePoint 2010 project to

deploy the add-in.

1. Open Visual Studio 2010 and open the starter solution at

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\Solution

Deployment\SolutionDeployment.sln

2. Publish the InvoiceTemplate project

a. Right click InvoiceTemplate in the Solution Explorer and click Properties

b. In the Publish tab, verify the version is 1.0.0.0

c. Right click InvoiceTemplate in the Solution Explorer and click Publish

d. In the first dialog page leave the publish location as publish\ and click Next

e. In the next page select From a CD-ROM or DVD-ROM and click Next

f. In the last page verify the information is correct and click Finish

3. Add a new SharePoint 2010 project to the solution

a. Click File -> Add -> New Project

b. In the Visual C#\Visual Basic -> SharePoint -> 2010 template, choose the Empty

SharePoint Project option

c. Enter a name of InvoiceApplication and click OK

d. Enter http://intranet.contoso.com/sites/Deployment as the site

e. Choose Deploy as a farm solution and click Finish

Task 2 – Create the SharePoint objects needed to deploy the Invoice Document

Page 16: Security and Deployment Lab

In this task, you will create the content type and module used to deploy the add-in.

1. Create a new Content Type named InvoiceDocument to reference the document template

a. Right click the InvoiceApplication project in the Solution Explorer and click Add ->

New Item

b. Select the Content Type item and create a new item named InvoiceDocument

c. In the dialog choose a base type of Document and click Finish

d. In the Elements.xml file that opened for you, change the Name to InvoiceDocument

e. After the FieldRefs nodes, add the following DocumentTemplate node.

XML

<DocumentTemplate TargetName="Addin/InvoiceTemplate.dotx" />

f. Save the changes to the content type’s Elements.xml file

2. Embed a new Module Item named Addin within the InvoiceDocument content type

a. Right click the InvoiceDocument content type in the Solution Explorer and click Add

-> New Item

b. In the dialog select the Module template

c. Name it Addin and click Add to create the new module

d. Delete the Sample.txt file that was added automatically

e. Open the Elements.xml file in the new Addin item and modify the Module element

to match the following example

XML

<Module Name="Addin" Url="_cts/InvoiceDocument" RootWebOnly ="TRUE">

Note: The Url attribute determines where it the site collection the files are deployed.

The RootWebOnly attribute determines that this module will only be deployed at the

site collection level.

3. Add the published InvoiceDocument add-in files to the new Addin module

a. Right click Addin and click Add -> Existing Item

b. In the dialog navigate to

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\

SolutionDeployment\InvoiceTemplate\publish

c. Select the InvoiceTemplate.dotx and InvoiceTemplate.vsto files and click Add

Page 17: Security and Deployment Lab

d. Right click Addin and select Add -> New Folder and rename it Application Files

e. Right click Application Files and select Add -> New Folder and rename it

InvoiceTemplate_1_0_0_0

f. Right click InvoiceTemplate_1_0_0_0 and click Add -> Existing Item

g. In the dialog navigate to C:\Office2010DeveloperTrainingKit\Labs\Deployment\

Source\[language]\Starter\SolutionDeployment\InvoiceTemplate\publish\Applica

tion Files\InvoiceTemplate_1_0_0_0

h. Select all files in the folder and click Add

4. Create a new list template based on the Invoice Document content type

a. Right click the InvoiceApplication project and click Add -> New Item

b. In the dialog select the List Definition from Content Type template

c. Give it a name of InvoiceDocumentLibrary and click Add

d. In the wizard enter a display name of Invoice Document Library

e. Verify the content type selected is Invoice Document

f. Uncheck the Add a list instance for this list definition and click Finish

5. Update the list template to relate the content type to the folder containing the addin

a. Open the Schema.xml file in the InvoiceDocumentLibrary item

b. In the List element at the top of the document, add the EnableContentTypes

attribute to turn on content types

XML

EnableContentTypes=”TRUE”

c. Inside the ContentType node add the following Folder element

XML

<ContentType ID="0x01010070158d26ab254e4288119c31012da458" ...>

<FieldRefs>

</FieldRefs>

<Folder TargetName="InvoiceDocument" />

</ContentType>

Note: Only add the Folder element, do not modify the ID attribute of the ContentType

element

d. Save your changes to the Schema.xml file

Page 18: Security and Deployment Lab

Task 3 – Create the Feature that will deploy the InvoiceDocument Add-in

In this task, you will create the feature that will deploy the SharePoint items you just created.

1. Update the feature’s name and verify it contains all the necessary deployment items

a. In the Solution Explorer, locate Feature1 in the Features folder and rename it to

SiteFeature

b. Double click SiteFeature in the Solution Explorer to open the designer

c. Update the title to InvoiceApplication Site Feature

d. Change the scope of the feature to Site

2. Create a feature receiver that will update the addin path stored in the template any time the

feature is activated

a. Right click SiteFeature in the Solution Explorer and click Add Event Receiver

b. Right click InvoiceApplication and select Add Reference

c. Add a reference to

Microsoft.VisualStudio.Tools.Applications.ServerDocument.v10.0

d. Add the following using statements to the new feature receiver

C#

using System.IO;

using Microsoft.VisualStudio.Tools.Applications;

Visual Basic

Imports System.IO

Imports Microsoft.VisualStudio.Tools.Applications

e. Uncomment the FeatureActivated method

f. Insert the following code to fine the SPFile object storing the document template

C#

SPSite site = properties.Feature.Parent as SPSite;

SPContentType contentType =

site.RootWeb.ContentTypes["InvoiceDocument"];

SPFile file = site.RootWeb.GetFile(contentType.DocumentTemplateUrl);

Visual Basic

Dim site As SPSite = TryCast(properties.Feature.Parent, SPSite)

Dim contentType As SPContentType =

site.RootWeb.ContentTypes("InvoiceDocument")

Dim file As SPFile =

site.RootWeb.GetFile(contentType.DocumentTemplateUrl)

Page 19: Security and Deployment Lab

g. Insert the following code to write the contents of the document template to a

temporary file.

C#

string tempFile = Path.GetTempFileName() + ".dotx";

File.WriteAllBytes(tempFile, file.OpenBinary());

Visual Basic

Dim tempFile As String = Path.GetTempFileName() & ".dotx"

File.WriteAllBytes(tempFile, file.OpenBinary())

h. Use ServerDocument to open the file and modify the DeploymentManifestUrl

C#

try

{

using (ServerDocument document = new ServerDocument(tempFile))

{

string url = site.RootWeb.Url.EndsWith("/") ?

site.RootWeb.Url :

site.RootWeb.Url + "/";

document.DeploymentManifestUrl =

new Uri(url + contentType.ResourceFolder.Url +

"/Addin/InvoiceTemplate.vsto");

document.Save();

}

using (FileStream tempFileStream = File.Open(tempFile,

FileMode.Open))

file.SaveBinary(tempFileStream);

}

Visual Basic

Try

Using document As New ServerDocument(tempFile)

Dim url As String = If(site.RootWeb.Url.EndsWith("/"),

site.RootWeb.Url, site.RootWeb.Url & "/")

document.DeploymentManifestUrl = New Uri(url &

contentType.ResourceFolder.Url & "/Addin/InvoiceTemplate.vsto")

document.Save()

End Using

Using tempFileStream As FileStream = File.Open(tempFile,

FileMode.Open)

Page 20: Security and Deployment Lab

file.SaveBinary(tempFileStream)

End Using

End Try

i. Clean up by deleting the temporary file

C#

finally

{

File.Delete(tempFile);

}

Visual Basic

Finally

File.Delete(tempFile)

End Try

3. Deploy the completed SharePoint application

a. Right click InvoiceApplication in the Solution Explorer and click Deploy

Task 4 – Deploy and test the new Invoice Document template

In this task, you will finish the deployment of the new add-in by registering the certificates and adding

the appropriate paths to Word’s trusted locations.

1. Register the certificates used to sign the add-in manifest files

a. Run a new Visual Studio Command Prompt (2010) in Programs -> Microsoft Visual

Studio 2010 -> Visual Studio Tools

b. Change the directory to

C:\Office2010DeveloperTrainingKit\Labs\Deployment\Source\[language]\Starter\

SolutionDeployment\InvoiceTemplate

c. Execute the following commands to register the certificates

CMD

certmgr –add –c InvoiceTemplate_TemporaryKey.pfx –s Root

certmgr –add –c InvoiceTemplate_TemporaryKey.pfx –s TrustedPublisher

2. Start Word 2010 and add the new site to the trusted location

a. Open Office Word 2010

b. Click the File tab for Backstage and then click Options

c. In the options dialog, choose Trust Center and click Trust Center Settings

Page 21: Security and Deployment Lab

d. Select Trusted Locations and verify Allow Trusted Locations on my network is

checked

e. Click Add new location

f. Enter a path of http://intranet.contoso.com/sites/Deployment

g. Check the Subfolders of this location are also trusted checkbox

h. Click OK to close all of the dialog

i. Close Word 2010

3. Create a new list using the Invoice Document Library template and test the new document

button

a. Open Internet Explorer and navigate to

http://intranet.contoso.com/sites/Deployment

b. Click the All Site Content link on the Navigation bar

c. Click the Create button then click the Invoice Document Library link

d. Enter a name of Invoices and click Create

e. In the new document library select the Documents ribbon and click New Document

f. Verify Word 2010 opens and downloads the addin related to the document

Summary

In this lab exercise, you learned how use the VSTO Runtime 2010 to deploy several add-ins. The first

add-in highlighted the automatic update capabilities of Office add-ins. The second add-in used a post

deployment action to do final setup for the add-in. The third add-in was actually multiple add-ins

deployed in a single ClickOnce manifest. The fourth add-in showed how to deploy a document template

in a SharePoint solution.

Page 22: Security and Deployment Lab

Appendix

No Items

No Appendix content