Share via


Specifying Unbound References

Retired Content

This content is outdated and is no longer being maintained. It is provided as a courtesy for individuals who are still using these technologies.
This page may contain URLs that were valid when originally published, but now link to sites or pages that no longer exist.

A Boolean attribute of the recipe element, named Bound, is used to specify whether a recipe is bound. By default, a recipe is bound, so you need to use this attribute to explicitly state that the recipe is unbound, as shown in the following XML code example.

<Recipe Name="ExampleRecipe" Bound="false">

Unbound references contain target conditions that the Recipe Framework calls to see if a reference should be shown on selected elements. The selection condition is specified in code so unbound references are instances of classes that you need to write.

The following code example shows an unbound reference class defining the target condition IsEnabledFor. This target condition evaluates to True when the selected element is a C# class library project.

using System;
using System.Text;
using System.Runtime.Serialization;
using Microsoft.Practices.RecipeFramework.VisualStudio.Templates;
using EnvDTE;
using VSLangProj;

namespace PackageNamespace.References
{
  [Serializable]
  public class ClassLibraryReference : UnboundTemplateReference
  {
    public ClassLibraryReference(string template) : base(template)
    {
    }
    
    public override bool IsEnabledFor(object target)
    {
      return target is Project && ((Project)target).Kind == PrjKind.prjKindCSharpProject && int)((Project)target).Properties.Item("OutputType").Value == (int)prjOutputType.prjOutputTypeLibrary;
    }
    
    public override string AppliesTo
    {
      get { return "All C# projects that are class libraries"; }
    }
    
    #region ISerializable Members
    /// <summary>
    /// Required constructor for deserialization.
    /// </summary>
    protected ClassLibraryReference(SerializationInfo info, StreamingContext context) : base(info, context)
    {
    }
    #endregion ISerializable Members
  }
}

The Recipe Framework contains a library action, CreateUnboundReferenceAction that you should use to create unbound recipe and template references as part of a binding recipe. Binding recipes should be used to create unbound recipe references because they are executed when a template that can enable the Guidance Package is unfolded or when the Guidance Package is specifically enabled in Guidance Package Manager. For more information about binding recipes, see Understanding Recipes.

The following XML code example shows the binding recipe specified in the Guidance Package configuration file created when you create a new Guidance Package from the Guidance Package Development template. This recipe uses CreateUnboundReferenceAction to create a recipe reference for the recipe GenerateRepeatingClass. This recipe is implemented by a library class, Microsoft.Practices.RecipeFramework.

Library.AssetReferences.UnboundReferences.CSharpProjectRecipeReference. It also creates two template references.

<Recipe Name="BindingRecipe">
  <Types>
    <TypeAlias Name="RefCreator" Type="Microsoft.Practices.RecipeFramework.Library.Actions.CreateUnboundReferenceAction, Microsoft.Practices.RecipeFramework.Library"/>
  </Types>
  <Caption>Creates unbound references to the guidance package</Caption>
  <Actions>
    <Action Name="CreateSampleUnboundRecipeRef" Type="RefCreator" AssetName="GenerateRepeatingClass"
      ReferenceType="Microsoft.Practices.RecipeFramework.Library.AssetReferences.UnboundReferences.CSharpProjectRecipeReference, Microsoft.Practices.RecipeFramework.Library" />
    <Action Name="CreateSampleUnboundTemplateRef" Type="RefCreator" AssetName="Projects\SampleLibrary\SampleLibrary.vstemplate"
      ReferenceType="PackageNamespace.References.SolutionFolderAReference, PackageName" />
    <Action Name="CreateSampleUnboundItemTemplateRef" Type="RefCreator" AssetName="Items\Class.vstemplate"
      ReferenceType="PackageNamespace.References.ClassLibraryReference, PackageName" />
    <Action Name="CreateUnboundItemTemplateRef" Type="RefCreator" AssetName="AddItemTemplateReference"
      ReferenceType="Microsoft.Practices.RecipeFramework.Library.AssetReferences.UnboundReferences.CSharpProjectRecipeReference, Microsoft.Practices.RecipeFramework.Library" />
    <Action Name="CreateUnboundProjectTemplateRef" Type="RefCreator" AssetName="AddProjectTemplateReference"
      ReferenceType="PackageNamespace.References.SolutionFolderRecipeReference, PackageName" />
  </Actions>
</Recipe>

See also

Developing Recipes | Specifying Command Bars | Specifying Bound References | Gathering Arguments| The AddMainClass Recipe