How to: Build and Run the ShapeAppClickOnceCSharp Sample
The ShapeAppClickOnceCSharp sample extends the ShapeAppCSharp sample host application by adding support for ClickOnce deployment.
For more information, see Securing and Deploying Add-Ins.
The procedures in this topic show how to build and run the ShapeAppClickOnceCSharp sample. These tasks appear in the following order:
Extract the ShapeAppClickOnceCSharp sample.
Open the ShapeAppClickOnceCSharp sample in Visual Studio and build it.
Register the ShapeAppClickOnceCSharp sample. Doing this lets you build and debug the sample add-ins, and use the project templates that are included with the ShapeAppClickOnceCSharp sample to create your own add-ins.
Build the sample add-in.
Create a test certificate to sign the application and deployment manifests.
Create the application and deployment manifests.
Install and load the add-in.
(Optional) Unregister ShapeAppClickOnceCSharp. Doing this removes the registry entries that let you build and debug the sample add-in, and also removes the entries that let you use the project templates that are included with ShapeAppClickOnceCSharp.
To extract ShapeAppClickOnceCSharp
Create a folder named ShapeAppSamples at the root of the Windows system drive (%SystemDrive%), and then create a subfolder named ShapeAppClickOnceCSharp. For example, if the system drive is C, the path would be C:\ShapeAppSamples\ShapeAppClickOnceCSharp.
Note
Although you can extract ShapeAppClickOnceCSharp to any folder, the following procedures assume that you extract it to the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp folder.
Open the Visual Studio Tools for Applications samples folder.
By default, the samples folder is located at %ProgramFiles%\Visual Studio Tools for Applications 2.0 SDK\build number\Visual Studio Tools for Applications\Samples on 32-bit versions of Windows, or at %ProgramFiles(x86)%\Visual Studio Tools for Applications 2.0 SDK\build number\Visual Studio Tools for Applications\Samples on 64-bit versions of Windows.
Right-click the ShapeAppClickOnceCSharp.zip file, and then click Extract All.
Note
This step assumes that the system is set to open .zip files by using Compressed (zipped) Folders. If the system is set to open .zip files by using another program, follow the instructions of that program to extract the contents of ShapeAppClickOnceCSharp.zip.
Follow the instructions in the Extract Compressed (Zipped) Folders wizard to extract the contents of ShapeAppClickOnceCSharp.zip to the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp folder.
To build ShapeAppClickOnceCSharp
Start Visual Studio 2008. If you are using Windows Vista as the operating system, start Visual Studio 2008 by using the Run as Administrator option.
On the File menu, point to Open, and then click Project/Solution.
In the Open Project dialog box, locate the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp folder.
Select the ShapeAppClickOnceCSharp.sln file, and then click Open.
On the Build menu, click Build Solution. Verify that the solution builds without errors.
To register ShapeAppClickOnceCSharp
Open a Command Prompt window. If you are using Windows Vista as the operating system, open a Command Prompt window by using the Run as Administrator option.
Run the following command.
cd "%SystemDrive%\ShapeAppSamples\ShapeAppClickOnceCSharp"
Note
If your development computer has a 64-bit operating system, make sure that you open a 32-bit Command Prompt window. The script file that registers ShapeAppClickOnceCSharp can be run only in a 32-bit Command Prompt window.
Type the following command to run the SetupShapeAppClickOnceCSharp.js script file. This script file registers ShapeAppClickOnceCSharp with Visual Studio Tools for Applications and configures the project templates so that they can be used in Visual Studio 2008.
cscript SetupShapeAppClickOnce.js
For more information about how to register host applications, see Registering the Host Application.
Note
Each version of the ShapeAppCSharp sample provides a setup script. All setup scripts write to the same location in the registry. Therefore, you can only use the setup script to register one version of the ShapeAppCSharp sample application at a time.
To build the sample add-in
On the File menu, point to Open, and then click Project/Solution.
In the Open Project dialog box, locate the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp\sample addIns\CSharp folder.
Note
The following instructions assume that you are building the Visual C# version of the add-ins. For Visual Basic versions of the add-ins, see the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp\sample addIns\VisualBasic folder.
Select the ShapeAppCSharpAddIns.sln file, and then click Open.
On the Build menu, click Build Solution. Verify that the solution builds without errors.
When you build the solution, the add-in assemblies are automatically copied as follows:
(For Windows XP and Windows Server 2003) ShapeAppCSharpAppAddIn.dll is copied to %UserProfile%\My Documents\ShapeAppCSharp\AppAddIns\ShapeAppCSharpAppAddIn.
(For Windows Vista) ShapeAppCSharpAppAddIn.dll is copied to %UserProfile%\Documents\ShapeAppCSharp\AppAddIns\ShapeAppCSharpAppAddIn.
To create a certificate
On the File menu, point to Open, and then click Project/Solution.
In the Open Project dialog box, locate the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp folder.
Select the ShapeAppClickOnceCSharp.sln file, and then click Open.
On the Project menu, click ShapeAppClickOnceCSharp Properties.
On the Signing tab, select Sign the ClickOnce manifests.
Click Create Test Certificate.
In the Create Test Certificate dialog box, type test in the Enter Password for new file ShapeAppClickOnceCSharp_TemporaryKey.pfx and Confirm your password boxes.
Clear Sign the ClickOnce manifests.
In the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp\core folder, copy ShapeAppClickOnceCSharp_TemporaryKey.pfx, and then paste it in the drive:\ShapeAppSamples\ShapeAppClickOnceCSharp\Sample AddIns\CSharp\AppLevel\Bin\Debug folder.
To create the ClickOnce application and deployment manifests for the add-in
In Visual Studio 2008, open the Command Window. If you are using Windows Vista as the operating system, open the Command Window by using the Run as Administrator option.
Run the following command.
cd "%SystemDrive%\ShapeAppSamples\ShapeAppClickOnceCSharp\sample addIns\CSharp\Applevel\bin\debug"
Run the following command to create an application manifest.
mage -New Application -ToFile ShapeAppCSharpAppAddIn.dll.manifest -Name "Shape App CSharp Add-in with ClickOnce manifests" -Version "1.0.0.0" -FromDirectory .
The ShapeAppCSharpAppAddIn.dll.manifest file is created.
Open ShapeAppCSharpAppAddIn.dll.manifest in the Visual Studio XML editor.
Add the following text to the end of the file but before the last </asmv1:assembly> element:
<vstav2:addIn xmlns:vstav2="urn:schemas-microsoft-com:vsta.v2"> <vstav2:entryPoints> <vstav2:entryPoint class="ShapeAppCSharpAppAddIn.AppAddIn"> <assemblyIdentity name="ShapeAppCSharpAppAddIn" version="1.0.2897.25791" language="neutral" processorArchitecture="msil" /> </vstav2:entryPoint> </vstav2:entryPoints> <vstav2:update enabled="true"> <vstav2:expiration maximumAge="7" unit="days" /> </vstav2:update> </vstav2:addIn>
Save and close ShapeAppCSharpAppAddIn.manifest.
In the Command Window, run the following command to sign the application manifest. Type your password for the certificate at the end of this command.
mage -sign ShapeAppCSharpAppAddIn.dll.manifest -CertFile ShapeAppClickOnceCSharp_TemporaryKey.pfx -Password test
Run the following command to create a deployment manifest.
mage -New Deployment -ToFile ShapeAppCSharpAppAddIn.vsta -Name "Shape App CSharp Add-in with ClickOnce manifests" -Version "1.0.0.0" -AppManifest ShapeAppCSharpAppAddIn.dll.manifest
Run the following command to sign the deployment manifest. Type your password for the certificate at the end of this command.
mage -sign ShapeAppCSharpAppAddIn.vsta -CertFile ShapeAppClickOnceCSharp_TemporaryKey.pfx -Password test
To install and load the ClickOnce add-in
In Visual Studio, on the Project menu, click ShapeAppClickOnceCSharp Properties.
On the Debug tab, in the command-line arguments, type the following command.
/clickonce:"C:\ShapeAppSamples\ShapeAppClickOnceCSharp\sample addIns\CSharp\Applevel\bin\debug\ShapeAppCSharpAppAddIn.vsta"
Press F5.
The ShapeApp application starts.
Verify that ShapeApp displays two sets of messages. The first set of messages is displayed by the add-in that you installed and loaded by using ClickOnce. The second set of messages is displayed by the add-in that you created by building the ShapeAppCSharpAddIns solution.
Exit ShapeApp.
To unregister ShapeAppClickOnceCSharp
Open a Command Prompt window. If you are using Windows Vista as the operating system, open a Command Prompt window by using the Run as Administrator option.
Run the following command.
cd "%SystemDrive%\ShapeAppSamples\ShapeAppClickOnceCSharp"
Note
If your development computer has a 64-bit operating system, make sure that you open a 32-bit Command Prompt window. The script file that unregisters ShapeAppClickOnceCSharp can be run only in a 32-bit Command Prompt window.
Type the following command to run the RemoveShapeAppCSharp.js script file. This script file removes registry entries that let you build and debug the sample add-in, and also removes entries that let you use the project templates that are included with ShapeAppClickOnceCSharp.
cscript RemoveShapeAppCSharp.js
Note
This command might require several minutes to be completed.
See Also
Tasks
How to: Build and Run the ShapeAppCSharp Sample
How to: Build and Run the ShapeAppBasicCSharp Sample
How to: Build and Run the ShapeAppMacroRecordingCSharp Sample
How to: Build and Run the ShapeAppDynamicProgrammingModelCSharp Sample
How to: Build and Run the ShapeAppBasicMFC Sample
Walkthrough: Integrating Visual Studio Tools for Applications with ShapeApp