Thanks Jose, you answer has helped me very much.
Your sugestion is the solucion.
There the solution:
///////////////////////////////////////////////////// Class ProjectAssemblyReference //////////////////////////////////////////////////// using System; using System.Text; using System.Runtime.Serialization; using Microsoft.Practices.RecipeFramework; using EnvDTE; using VSLangProj; using Microsoft.Practices.Common;
using System.Security.Permissions;
namespace Microsoft.Services.BF.GuidancePackage.References { [Serializable] public class ProjectAssemblyReference : UnboundRecipeReference, IAttributesConfigurable { private string assemblyNameName; private const string AssemblyNameAttribute = "AssemblyReferenceName";
public ProjectAssemblyReference(string template) : base(template) { }
public override bool IsEnabledFor(object target) { VSProject vsProject = GetProject(target); if (vsProject != null) { //Iterate in each one of reference in the project, to determine the reference expected foreach (Reference reference in vsProject.References) { if (reference.Name == assemblyNameName) return true; } }
return false;
}
public override string AppliesTo { get { return "All project with reference to FeeManagement assembly"; } }
#region ISerializable Members
/// <summary> /// Required constructor for deserialization. /// </summary> protected ProjectAssemblyReference(SerializationInfo info, StreamingContext context) : base(info, context) { assemblyNameName = info.GetString(AssemblyNameAttribute); }
/// <summary> /// Provides a serialization member that derived classes can override to add /// data to be stored for serialization. /// </summary> [SecurityPermission(SecurityAction.Demand, SerializationFormatter = true)] protected override void GetObjectData(SerializationInfo info, StreamingContext context) { base.GetObjectData(info, context); info.AddValue(AssemblyNameAttribute, assemblyNameName); } #endregion ISerializable Members
#region IAttributesConfigurable Members
/// <summary> /// Configures the component using the dictionary of attributes specified /// in the configuration file. /// </summary> /// <param name="attributes">The attributes in the configuration element.</param> public void Configure(System.Collections.Specialized.StringDictionary attributes) { if (attributes.ContainsKey(AssemblyNameAttribute)) { assemblyNameName = attributes[AssemblyNameAttribute]; } }
#endregion
/// <summary> /// Resolve the conflict in the selecction of Project or ProjectItem. /// </summary> /// <param name="target"></param> /// <returns> /// Return the normalized VSProject use to get the reference /// </returns> private VSProject GetProject(object target) { //If It is project Project project = target as Project;
if (project != null) return project.Object as VSProject;
//If It is project item ProjectItem projectItem = target as ProjectItem;
if (projectItem != null) return projectItem.ContainingProject.Object as VSProject;
//return default return null; }
} }
And it is use in the <Recipe Name="BindingRecipe">:
<Action Name="FeeClassRef" Type="RefCreator" AssetName="FeeClass" ReferenceType="Microsoft.Services.BF.GuidancePackage.References.ProjectAssemblyReference, Microsoft.Services.BF.GuidancePackage" AssemblyReferenceName="Microsoft.Services.BF.FeesManagement"/>
The class take the target parameter, and verify if it is project or projectitem, recover the vsproject, for get the reference project. Iterate by each reference and compare if it have the reference define in the AssemblyReferenceName attribute.
Many Thanks
|