Use Case
| • | You want to create a .NET assembly that contains plugin functionality to be discovered and loaded by the Framework at runtime. |
Relevant Architecture
Relevant Types
| • | PluginAttribute |
Sample Code
// This code is typically in the project's AssemblyInfo.cs file.
using System.Reflection;
using System.Runtime.CompilerServices;
using ClearCanvas.Common;
// This attribute tells the Framework that the assembly is a plugin.
[assembly: Plugin()]
//
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
// They are typically auto-generated by Visual Studio, so you may already have
// these attributes - in this case, you should just edit the existing ones.
//
[assembly: AssemblyTitle("Standard Tools Plugin")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("ClearCanvas Inc.")]
[assembly: AssemblyProduct("ClearCanvas Workstation")]
[assembly: AssemblyCopyright("Copyright (c) 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// ... (other assembly: attributes here)
Remarks
A plugin is nothing more than a .NET assembly that has been marked with the Plugin assembly level attribute. At startup, the Framework finds all assemblies in the /plugins folder that have this attribute and loads them dynamically. The Plugin attribute is in the ClearCanvas.Common namespace, so be sure to include the using line as well!
Using the Wizard When Building Against the Source
The ClearCanvas SDK provides some useful wizards to make common tasks a little easier. One such task is creating a plugin. To use the wizard to create a plugin:
| 1. | Open the \Trunk\ImageViewer\ImageViewer.sln |
| 2. | Add a new project to the solution. Under Project Types, select Visual C#. If the SDK has been installed properly, you’ll see four ClearCanvas templates under My Templates. The ClearCanvas Plugin template creates a plugin that has no user interface. The ClearCanvas WinForms View Plugin creates a plugin that can have a user-defined UI. Be sure to select templates labelled "for source". |

| 3. | Name your project and click OK. |
| 4. | Add a reference to the ClearCanvas.Common project (at minimum) and whatever other projects you may need. |
| 5. | Add a new <PluginFiles> line to the \Trunk\ImageViewer\ImageViewer_dist.proj file. This is an MSBuild file that gets executed as a post-build step and ensures that all necessary binaries, including your plugin, get copied to the right place for execution (i.e., \Trunk\Desktop\Executable\Debug). |
| 6. | Under Project Dependencies, make ClearCanvas.Desktop.Executable dependent on the project you just added. This will ensure that the post build step executes properly. |
| 7. | Build the solution. |
| 8. | Follow the instructions on running the code. |
Using the Wizard When Building Against the Binaries
| 1. | Open up the New Project dialog in Visual Studio (File > New > Project) and create a blank solution (i.e. one with no projects). |
| 2. | Repeat step 2 above, except select only templates labelled "for binary". |
| 3. | Name your project and click OK. |
| 4. | Build the project. This will create a distribution of CC Workstation in <yourSolutionDirectory>\build. |
| 5. | Add whatever additional project references you require from the SDK's bin\redistributable directory. |
| 6. | Go to the Project Properties and set Start external program to <yourSolutionDirectory>\build\Debug\ClearCanvas.Desktop.Executable.exe. and Working directory to <yourSolutionDirectory>\build\Debug. |

| 6. | Run the project. |
Examples in Code Base
| • | N/A |