How to: Build and Run the ShapeAppDynamicProgrammingModelCSharp Sample
The ShapeAppDynamicProgrammingModelCSharp sample extends the ShapeAppCSharp sample host application by dynamically adding and removing host items and host objects in the project. As you interact with drawings and shapes in the application, ShapeApp adds, removes, and renames documents (host items in ShapeApp) and shapes (host controls in ShapeApp) in the open project.
For more information, see Dynamically Creating and Modifying Host Items and Host Objects in an Add-in Project.
To build and run the ShapeAppDynamicProgrammingModelCSharp sample, perform the following steps:
Extract the ShapeAppDynamicProgrammingModelCSharp sample.
Open the ShapeAppDynamicProgrammingModelCSharp sample in Visual Studio and build it.
Register the ShapeAppDynamicProgrammingModelCSharp sample. This enables you to build and debug the sample add-ins, and to use the project templates that are included with the ShapeAppDynamicProgrammingModelCSharp sample to create your own add-ins.
Run the ShapeAppDynamicProgrammingModelCSharp sample.
Add, remove, and rename documents and shapes in the add-in project. As you do, the programming model of the project is immediately updated to make the new objects available to code.
(Optional) Unregister ShapeAppDynamicProgrammingModelCSharp. 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 ShapeAppDynamicProgrammingModelCSharp.
To extract ShapeAppDynamicProgrammingModelCSharp
Create a folder named ShapeAppSamples at the root of the Windows system drive (%SystemDrive%), and then create a subfolder named ShapeAppDynamicProgrammingModelCSharp. For example, if your system drive is C, the directory would be C:\ShapeAppSamples\ShapeAppDynamicProgrammingModelCSharp.
Note
Although you can extract ShapeAppDynamicProgrammingModelCSharp to any folder, the following procedures assume that you extract ShapeAppDynamicProgrammingModelCSharp to the drive:\ShapeAppSamples\ShapeAppDynamicProgrammingModelCSharp 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 ShapeAppDynamicProgrammingModelCSharp.zip file, and then click Extract All.
Note
This step assumes that your system is set to open .zip files using Compressed (zipped) Folders. If your system is set to open .zip files with another program, follow the instructions of that program to extract the contents of ShapeAppDynamicProgrammingModelCSharp.zip.
Follow the instructions in the Extract Compressed (Zipped) Folders wizard to extract the contents of ShapeAppDynamicProgrammingModelCSharp.zip to the drive:\ShapeAppSamples\ShapeAppDynamicProgrammingModelCSharp folder.
To build ShapeAppDynamicProgrammingModelCSharp
Start Visual Studio 2008. If you are using Windows Vista as your 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, navigate to the drive:\ShapeAppSamples\ShapeAppDynamicProgrammingModelCSharp folder.
Select the ShapeAppDynamicProgrammingModelCSharp.sln file, and then click Open.
On the Build menu, click Build Solution. Verify that the solution builds without errors.
To register ShapeAppDynamicProgrammingModelCSharp
Open a Command Prompt window. If you are using Windows Vista as your operating system, open a Command Prompt window by using the Run as Administrator option.
Run the following command.
cd "%SystemDrive%\ShapeAppSamples\ShapeAppDynamicProgrammingModelCSharp"
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 ShapeAppDynamicProgrammingModelCSharp can be run only in a 32-bit Command Prompt window.
Type the following command to run the SetupShapeAppDynamicProgrammingModelCSharp.js script file. This script file registers ShapeAppDynamicProgrammingModelCSharp with Visual Studio Tools for Applications and configures the project templates so that they can be used from Visual Studio 2008.
cscript SetupShapeAppDynamicProgrammingModelCSharp.js
For more information about registering host applications, see Registering the Host Application.
Note
This command might require several minutes to complete.
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 run ShapeAppDynamicProgrammingModelCSharp
- In Visual Studio, press F5 to run the application.
To add, remove, and rename documents and shapes
In ShapeAppCSharp, click File and then click Save. Save the add-in project to any directory on your development computer.
On the Customize menu of ShapeAppCSharp, click Create Document Add-In, and then click C# Project.
The Visual Studio Tools for Applications IDE appears and opens an add-in project in Project Explorer.
On the Drawings menu of ShapeAppCSharp, click Insert.
In the Visual Studio Tools for Applications IDE, verify that a new item named Drawing4.cs appears in Project Explorer.
In ShapeAppCSharp, drag a triangle onto an open document.
In the Visual Studio Tools for Applications IDE, double-click Drawing4.cs.
Drawing4.cs opens in the Code Editor.
In the Drawing4_Startup method, type Triangle1.Color = Color.Blue; to verify that you can access the triangle in code.
In ShapeAppCSharp, select the tab named Drawing4.
On the Drawings menu, click Rename. Rename Drawing4 to myDrawing.
In the Visual Studio Tools for Applications IDE, verify that Drawing4.cs now appears as Drawing4.cs (myDrawing) in Project Explorer.
On the Drawings menu of ShapeAppCSharp, click Delete.
In the Visual Studio Tools for Applications IDE, verify that the item named Drawing4 no longer appears in Project Explorer.
To unregister ShapeAppDynamicProgrammingModelCSharp
Open a Command Prompt window. If you are using Windows Vista as your operating system, open a Command Prompt window by using the Run as Administrator option.
Run the following command.
cd "%SystemDrive%\ShapeAppSamples\ShapeAppDynamicProgrammingModelCSharp"
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 ShapeAppDynamicProgrammingModelCSharp 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 to build and debug the sample add-in, and also removes entries that let you use the project templates that are included with ShapeAppDynamicProgrammingModelCSharp to create your own add-ins.
cscript RemoveShapeAppCSharp.js
Note
This command might require several minutes to complete.
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 ShapeAppClickOnceCSharp Sample
How to: Build and Run the ShapeAppBasicMFC Sample
Walkthrough: Integrating Visual Studio Tools for Applications with ShapeApp