Walkthrough: Copying a Document to the End User Computer after a ClickOnce Installation
[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
|
Applies to
|
|
Project type
Microsoft Office version
|
Using a ClickOnce post-deployment action, you can install document-level Office solutions, and then copy the document to the end user computer.
This requires that you modify the application manifest, and re-sign both the application and the deployment manifests before installation.
This walkthrough illustrates the following tasks:
-
Creating an Office solution to deploy.
-
Implementing a post-deployment action that copies a document to the end user's desktop.
-
Modifying the application manifest of the Office solution to run the post-deployment action.
-
Re-signing the application and deployment manifests.
Note
|
|
Your computer might show different names or locations for some of the Visual Studio user interface elements in the following instructions. The Visual Studio edition that you have and the settings that you use determine these elements. For more information, see Working with Settings.
|

Prerequisites
You need the following components to complete this walkthrough:

Creating a New Project
First, create an Excel workbook project.
To create a new Excel project
-
Create an Excel document-level project for the .NET Framework 3.5.
Name the project ExcelWorkbook, and save the project to the %USERPROFILE%\Documents\Visual Studio 10\Projects directory.
For more information, see How to: Create Office Projects in Visual Studio.
Visual Studio opens the new Excel workbook in the designer and adds the ExcelWorkbook project to SolutionExplorer.

Creating a Class Library Project that Defines the Post-Deployment Action
You must define the post-deployment action in a separate class library.
The post-deployment action performs copies the document to the end user computer.
To create a class library for the post-deployment action
-
In the File menu, point to Add, and then click New Project.
-
In the Add New Project dialog box, in the Installed Templates pane, click Windows.
-
In the Templates pane, click ClassLibrary.
-
Ensure that .NET Framework 3.5 remains selected as the target framework.
-
In the Name field, type FileCopyPDA, and then click OK.
-
In SolutionExplorer, click FileCopyPDA.
-
On the Project menu, click AddReference.
-
In the AddReference dialog box, in the .NET tab, click Microsoft.VisualStudio.Tools.Applications.Runtime and Microsoft.VisualStudio.ToolsApplications.ServerDocument, and then click OK.
-
In the Class1 code file, add the following using or Imports statements to the top of the code file.
Imports Microsoft.VisualStudio.Tools.Applications.Deployment
Imports Microsoft.VisualStudio.Tools.Applications
using Microsoft.VisualStudio.Tools.Applications.Deployment;
using Microsoft.VisualStudio.Tools.Applications;
using System.IO;
-
Rename the class to FileCopyPDA, and then add the following code to the FileCopyPDA class.
This code indicates that FileCopyPDA class inherits from IAddInPostDeploymentAction.
Public
Class FileCopyPDA
Implements IAddInPostDeploymentAction
public
class FileCopyPDA : IAddInPostDeploymentAction
-
Add the following code to implement the IAddInPostDeploymentAction.Execute method.
This code performs the following tasks:
-
Copies the Excel workbook file to the user's desktop if the solution is installed or updated.
-
Changes the _AssemblyLocation property from a relative path to a fully qualified path for the deployment manifest.
This is done using the AddCustomization and RemoveCustomization methods.
-
Deletes the file if the solution is uninstalled.
Sub Execute(ByVal args As AddInPostDeploymentActionArgs) Implements IAddInPostDeploymentAction.Execute
Dim dataDirectory AsString = "Data\ExcelWorkbook.xlsx"Dim file AsString = "ExcelWorkbook.xlsx"Dim sourcePath AsString = args.AddInPath
Dim deploymentManifestUri As Uri = args.ManifestLocation
Dim destPath AsString = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
Dim sourceFile AsString = System.IO.Path.Combine(sourcePath, dataDirectory)
Dim destFile AsString = System.IO.Path.Combine(destPath, file)
SelectCase args.InstallationStatus
Case AddInInstallationStatus.InitialInstall, AddInInstallationStatus.Update
File.Copy(sourceFile, destFile)
ServerDocument.RemoveCustomization(destFile)
ServerDocument.AddCustomization(destFile, deploymentManifestUri)
ExitSelectCase AddInInstallationStatus.Uninstall
If File.Exists(destFile) Then
File.Delete(destFile)
EndIfExitSelectEndSelectEndSub
public
void Execute(AddInPostDeploymentActionArgs args)
{
string dataDirectory = @"Data\ExcelWorkbook.xlsx";
string file = @"ExcelWorkbook.xlsx";
string sourcePath = args.AddInPath;
Uri deploymentManifestUri = args.ManifestLocation;
string destPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string sourceFile = System.IO.Path.Combine(sourcePath, dataDirectory);
string destFile = System.IO.Path.Combine(destPath, file);
switch (args.InstallationStatus)
{
case AddInInstallationStatus.InitialInstall:
case AddInInstallationStatus.Update:
File.Copy(sourceFile, destFile);
ServerDocument.RemoveCustomization(destFile);
ServerDocument.AddCustomization(destFile, deploymentManifestUri);
break;
case AddInInstallationStatus.Uninstall:
if (File.Exists(destFile))
{
File.Delete(destFile);
}
break;
}
}

Building and Publishing the Solution
Use the Publish Wizard or the Project Page to build and publish the Office solutions to your development computer.
To publish the Excel project
-
In SolutionExplorer, right-click the FileCopyPDA project, and then click Build.
-
In SolutionExplorer, right-click the ExcelWorkbook project, and then click Build.
-
In SolutionExplorer, right-click the ExcelWorkbook project, and then click Add Reference.
-
In the Add Reference dialog box, click the Projects tab.
-
Click FileCopyPDA, and click OK.
-
In Solution Explorer, click the ExcelWorkbook project.
-
On the Project menu, click New Folder.
-
Type Data and press the Enter key.
-
In Solution Explorer, click the Data folder.
-
On the Project menu, click Add Existing Item.
-
In the Add Existing Item dialog box, browse to the output directory for the ExcelWorkbook project.
-
Click ExcelWorkbook.xlsx, and click Add.
-
In SolutionExplorer, click ExcelWorkbook.xlsx.
-
In the Properties window, change the Build Action property to Content, and the Copy to Output Directory property to Copyif newer.
-
Publish the ExcelWorkbook project to the c:\publish folder.
For more information, see How to: Deploy an Office Solution by Using ClickOnce.

Modifying the Application Manifest
Use the XML editor in Visual Studio to modify the application manifest to run the File Copy post-deployment action.
To add the installation dependencies to the application manifest
-
Open the c:\publish directory through Windows Explorer.
-
Open the Application Files folder and then open the ExcelWorkbook_1_0_0_0 folder.
-
Open the ExcelWorkbook.dll.manifest file in a text editor.
-
Add following code after the </vstav3:update> element.
For the class attribute of the <vstav3:entryPoint> element, use the following syntax: NamespaceName.ClassName.
In this example, the namespace and class names are the same, so that the resulting entry point name is FileCopyPDA.FileCopyPDA.
<vstav3:postActions>
<vstav3:postAction>
<vstav3:entryPoint
class="FileCopyPDA.FileCopyPDA">
<assemblyIdentity
name="FileCopyPDA"
version="1.0.0.0"
language="neutral"
processorArchitecture="msil" />
</vstav3:entryPoint>
<vstav3:postActionData>
</vstav3:postActionData>
</vstav3:postAction>
</vstav3:postActions>

Re-signing the Manifests
The following procedure signs the application manifest and updates the deployment manifest.
This ensures that tampered files are not installed on end user computers.
To re-sign the application and deployment manifests
-
Copy the ExcelWorkbook_TemporaryKey.pfx certificate file from the %USERPROFILE%\Documents\Visual Studio 10\Projects\ExcelWorkbook\ExcelWorkbook solution directory into the c:\publish\Application Files\ExcelWorkbook_1_0_0_0 directory.
-
Open the Visual Studio command prompt.
-
Change to the c:\publish\Application Files\ExcelWorkbook_1_0_0_0 directory.
-
Sign the modified application manifest with the following command:
mage -sign ExcelWorkbook.dll.manifest -certfile ExcelWorkbook_TemporaryKey.pfx
The message "ExcelWorkbook.dll.manifest successfully signed" appears.
-
Change to the c:\publish directory.
-
Update and sign the deployment manifest with the following command:
mage -update ExcelWorkbook.vsto -appmanifest "Application Files\Ex
celWorkbook_1_0_0_0\ExcelWorkbook.dll.manifest" -certfile "Application Files\ExcelWorkbook_1_0_0_0\ExcelWorkbook_TemporaryKey.pfx"
The message "ExcelWorkbook.vsto successfully signed" appears.
-
Copy the ExcelWorkbook.vsto file to the c:\publish\Application Files\ExcelWorkbook_1_0_0_0 directory.

Testing the Post-Deployment Action
The following procedure ensures that the updated manifest installs the Excel workbook and copies the workbook to the end user's desktop.
To test the post-deployment action
-
Copy the c:\publish directory to a test computer.
-
Run the Setup.exe program, or if the prerequisites are already installed on the test computer, double-click the ExcelWorkbook.vsto deployment manifest.
The Microsoft Office Customization Installer appears.
-
Click Install.
The Microsoft Office Customization Installer dialog box shows the following message: "The Microsoft Office customization was successfully installed." The Excel workbook is copied to the end user's desktop.
-
Open the ExcelWorkbook.xlsx file from the desktop.

See Also
|
Visual Studio 2010 チュートリアル: ClickOnce インストール後にエンド ユーザーのコンピューターにドキュメントをコピーする
[このドキュメントはプレビュー版であり、後のリリースで変更されることがあります。 空白のトピックは、プレースホルダーとして挿入されています。]
|
対象
|
|
プロジェクトの種類
-
ドキュメント レベルのプロジェクト
-
アプリケーション レベルのプロジェクト
Microsoft Office のバージョン
|
ClickOnce 配置後のアクションを使用して、ドキュメント レベル Office ソリューションをインストールでき、エンドユーザーのコンピューターにドキュメントをコピーしできます。
これは、ため、アプリケーション マニフェストを変更し、アプリケーションとインストールの前に、配置マニフェストの両方再署名いる必要があります。
このチュートリアルでは、次の作業について説明します。
-
展開する Office ソリューションを作成します。
-
エンドユーザーのデスクトップに、ドキュメントをコピーする展開後のアクションを実装します。
-
展開後の操作を実行する Office ソリューションのアプリケーション マニフェストの変更。
-
マニフェスト、アプリケーションと展開を再署名します。
メモ
|
|
お使いのマシンで、Visual Studio ユーザー インターフェイスの一部の要素の名前や場所が、次の手順とは異なる場合があります。これらの要素は、使用している Visual Studio のエディションや独自の設定によって決まります。詳細については、「設定の操作」を参照してください。
|

[必須コンポーネント]
このチュートリアルを実行するには、次のコンポーネントが必要です。

新規プロジェクトの作成
Excel ブック プロジェクトを最初に、作成します。
新しい Excel プロジェクトを作成するには
-
.NET Framework 3. 5 の Excel ドキュメント レベル プロジェクトを作成します。
プロジェクト を ExcelWorkbook を名前をプロジェクトを付けて保存 %USERPROFILE%\Documents\Visual Studio 10\Projects ディレクトリにします。
詳細については、「方法 : Visual Studio で Office プロジェクトを作成します。」を参照してください。
Visual Studio opens the new Excel workbook in the designer and adds the ExcelWorkbook project to SolutionExplorer.

Post-Deployment の操作を定義するクラス ライブラリ プロジェクトの作成
定義、展開後の動作する必要があります別のクラス ライブラリ。
展開後のアクションは、コピーを実行する、ドキュメント、エンドユーザーのコンピューターをします。
展開後の動作のクラス ライブラリを作成するには
-
[で を追加、]、[新しいプロジェクト をクリックします。
-
新しいプロジェクトの追加 ダイアログ、 にインストールされたテンプレート ペインでボックス Windows 。
-
In the Templates pane, click ClassLibrary.
-
.NET Framework 3. 5 その は、ターゲット フレームワークとして選択したままを確認します。
-
名 フィールドで FileCopyPDA を入力して、[OK] の をクリックします。
-
In SolutionExplorer, click FileCopyPDA.
-
On the Project menu, click AddReference.
-
In the AddReference dialog box, in the .NET tab, click Microsoft.VisualStudio.Tools.Applications.Runtime and Microsoft.VisualStudio.ToolsApplications.ServerDocument, and then click OK.
-
または
ステートメントをインポート コード ファイルの先頭を使用して、次 クラス 1 のコード ファイルを追加します。
Imports Microsoft.VisualStudio.Tools.Applications.Deployment
Imports Microsoft.VisualStudio.Tools.Applications
using Microsoft.VisualStudio.Tools.Applications.Deployment;
using Microsoft.VisualStudio.Tools.Applications;
using System.IO;
-
FileCopyPDAに、クラスを変更クリックして追加次のコードを FileCopyPDA クラスにします。
このコードから FileCopyPDAIAddInPostDeploymentAction クラスを継承することを示します。
Public
Class FileCopyPDA
Implements IAddInPostDeploymentAction
public
class FileCopyPDA : IAddInPostDeploymentAction
-
IAddInPostDeploymentAction.Execute メソッドを実装する次のコード追加します。
このコードは次のタスクを実行します。
-
Excel ブック ファイルをユーザーのデスクトップにコピー、ソリューションがインストールまたは更新します。
-
_AssemblyLocation プロパティを相対パスから、配置マニフェストの完全修飾パスに変更します。
これは、AddCustomization および RemoveCustomization メソッドを使用します。
-
場合は、ソリューションがアンインストール ファイルを削除します。
Sub Execute(ByVal args As AddInPostDeploymentActionArgs) Implements IAddInPostDeploymentAction.Execute
Dim dataDirectory AsString = "Data\ExcelWorkbook.xlsx"Dim file AsString = "ExcelWorkbook.xlsx"Dim sourcePath AsString = args.AddInPath
Dim deploymentManifestUri As Uri = args.ManifestLocation
Dim destPath AsString = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory)
Dim sourceFile AsString = System.IO.Path.Combine(sourcePath, dataDirectory)
Dim destFile AsString = System.IO.Path.Combine(destPath, file)
SelectCase args.InstallationStatus
Case AddInInstallationStatus.InitialInstall, AddInInstallationStatus.Update
File.Copy(sourceFile, destFile)
ServerDocument.RemoveCustomization(destFile)
ServerDocument.AddCustomization(destFile, deploymentManifestUri)
ExitSelectCase AddInInstallationStatus.Uninstall
If File.Exists(destFile) Then
File.Delete(destFile)
EndIfExitSelectEndSelectEndSub
public
void Execute(AddInPostDeploymentActionArgs args)
{
string dataDirectory = @"Data\ExcelWorkbook.xlsx";
string file = @"ExcelWorkbook.xlsx";
string sourcePath = args.AddInPath;
Uri deploymentManifestUri = args.ManifestLocation;
string destPath = Environment.GetFolderPath(Environment.SpecialFolder.DesktopDirectory);
string sourceFile = System.IO.Path.Combine(sourcePath, dataDirectory);
string destFile = System.IO.Path.Combine(destPath, file);
switch (args.InstallationStatus)
{
case AddInInstallationStatus.InitialInstall:
case AddInInstallationStatus.Update:
File.Copy(sourceFile, destFile);
ServerDocument.RemoveCustomization(destFile);
ServerDocument.AddCustomization(destFile, deploymentManifestUri);
break;
case AddInInstallationStatus.Uninstall:
if (File.Exists(destFile))
{
File.Delete(destFile);
}
break;
}
}

構築と、ソリューションの発行
発行ウィザード または の [プロジェクト] ページを使用してビルドを開発用コンピューターに Office ソリューションを発行します。
Excel プロジェクトを発行するには
-
In SolutionExplorer, right-click the FileCopyPDA project, and then click Build.
-
In SolutionExplorer, right-click the ExcelWorkbook project, and then click Build.
-
In SolutionExplorer, right-click the ExcelWorkbook project, and then click Add Reference.
-
[参照の追加] ダイアログ ボックスの [プロジェクト] タブをクリックします。
-
を FileCopyPDA をクリックし、[OK] の をクリックします。
-
のソリューション エクスプローラー] で ExcelWorkbook プロジェクトをクリックします。
-
[プロジェクト] メニューの の新しいフォルダー] をクリックします。
-
のデータを入力し、 を入力してください キーを押します。
-
のソリューション エクスプローラー] で データ フォルダーをクリックします。
-
[プロジェクト] メニューの の [既存項目の追加] をクリックします。
-
既存項目の追加 ダイアログ ボックスで ExcelWorkbook プロジェクトの出力ディレクトリに参照します。
-
を ExcelWorkbook.xlsx をクリックし、 の追加をクリックします。
-
In SolutionExplorer, click ExcelWorkbook.xlsx.
-
In the Properties window, change the Build Action property to Content, and the Copy to Output Directory property to Copyif newer.
-
c:\publish フォルダーに ExcelWorkbook プロジェクトを発行します。
詳細については、「方法 : ClickOnce を使用して、Office ソリューションを展開します。」を参照してください。

アプリケーション マニフェストを変更します。
Visual Studio の XML エディターを使用して、ファイル コピーの展開後アクションを実行するアプリケーション マニフェストを変更します。
アプリケーション マニフェストに、インストールの依存関係を追加するには
-
Windows エクスプローラーを通じて c:\publish ディレクトリを開きます。
-
アプリケーション ファイル フォルダーを開き、 ExcelWorkbook_1_0_0_0 フォルダーを開きます。
-
テキスト エディターで ExcelWorkbook.dll.manifest ファイルを開きます。
-
</vstav3:update> 要素の後、次のコード追加します。
<vstav3:entryPoint> 要素のクラス属性に関して次の構文を使用します。 NamespaceName.ClassName.
この例では、名前空間とクラスの名前は同じ、結果のエントリ ポイント名が FileCopyPDA.FileCopyPDA ようにです。
<vstav3:postActions>
<vstav3:postAction>
<vstav3:entryPoint
class="FileCopyPDA.FileCopyPDA">
<assemblyIdentity
name="FileCopyPDA"
version="1.0.0.0"
language="neutral"
processorArchitecture="msil" />
</vstav3:entryPoint>
<vstav3:postActionData>
</vstav3:postActionData>
</vstav3:postAction>
</vstav3:postActions>

マニフェストを再署名
次のプロシージャ、アプリケーション マニフェストに署名し、配置マニフェストを更新します。
これにより、tampered ファイルがエンドユーザーのコンピューターにインストールされていないこと。
アプリケーションと配置マニフェストに再署名するには
-
c:\publish\Application Files\ExcelWorkbook_1_0_0_0 ディレクトリに %USERPROFILE%\Documents\Visual Studio 10\Projects\ExcelWorkbook\ExcelWorkbook ソリューション ディレクトリから ExcelWorkbook_TemporaryKey.pfx 証明書ファイルをコピーします。
-
Visual Studio コマンド プロンプトを開きます。
-
c:\publish\Application Files\ExcelWorkbook_1_0_0_0 ディレクトリに変更します。
-
次のコマンドを使って、変更されたアプリケーション マニフェストを署名します。
mage -sign ExcelWorkbook.dll.manifest -certfile ExcelWorkbook_TemporaryKey.pfx
メッセージ"ExcelWorkbook.dll.manifest しました"表示されます。
-
c:\publish ディレクトリに変更します。
-
更新し、次のコマンドで配置マニフェストの署名します。
mage -update ExcelWorkbook.vsto -appmanifest "Application Files\Ex
celWorkbook_1_0_0_0\ExcelWorkbook.dll.manifest" -certfile "Application Files\ExcelWorkbook_1_0_0_0\ExcelWorkbook_TemporaryKey.pfx"
メッセージ"ExcelWorkbook.vsto しました"表示されます。
-
c:\publish\Application Files\ExcelWorkbook_1_0_0_0 ディレクトリに、ExcelWorkbook.vsto ファイルをコピーします。

Post-Deployment、動作をテストします。
次の手順により、更新されたマニフェスト、ブックをインストールされエンド ユーザーのデスクトップに、ブックをコピーします。
展開後の操作をテストするには
-
テスト コンピューターに c:\publish ディレクトリをコピーします。
-
Setup.exe プログラムを実行するか、ExcelWorkbook.vsto 配置マニフェストをダブルクリック、前提条件が既にテスト コンピューターにインストールされている場合、します。
の Microsoft Office のカスタマイズのインストーラーが表示されます。
-
[インストール] をクリックします。
Microsoft Office のカスタマイズのインストーラー ダイアログ ボックスに次のメッセージが表示されます。"Microsoft Office のカスタマイズが正常にインストールします。Excel ブックがエンドユーザーのデスクトップにコピーされます。
-
デスクトップから ExcelWorkbook.xlsx ファイルを開きます。

参照
|