Defining Your Own Merge Strategy

Merge strategies are carried out by classes that implement the CodeSmith.Engine.IMergeStrategy interface.  After defining your own merge strategy, there are two ways that you can use it. First, you can specify a fully-qualified assembly name when calling the merge strategy from the command line:

/merge:MyMergeAssembly.MyMergeStragegy="MergeParameters=Sample Merge Parameters;Language=C#;"

Also, you can register your merge strategy with CodeSmtih Generator. This allows you to refer to your merge strategy by name and not by the types FullName.

Adding your merge strategy to the alias list allows you to call it by name when you use the /merge switch.

To do this, you will need to add a registry entry to the following node:

HKEY_CURRENT_USER\Software\CodeSmith\<VERSION>\MergeStrategyAlias\<NUMBER THAT DOESN'T EXIST (E.G., 5)>

Finally, you will need to create the following string registry values: Name and TypeName. Here is an entry of an example that ships with CodeSmith Generator, the contents of the code below is an registry export.

Windows Registry Editor Version 5.00
 
[HKEY_CURRENT_USER\Software\CodeSmith\<VERSION>\MergeStrategyAlias\5]
"Name"="PreserveRegions"
"TypeName"="CodeSmith.Engine.PreserveRegionsMergeStrategy,CodeSmith.Engine"